Edits history of script submission #23398 for ' Get Deal (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Deal
     * Retrieve a deal by record ID (or by a unique property via `id_property`), with the properties and associated object types you list.
     */
    export async function main(
      auth: RT.Hubspot,
      deal_id: string,
      properties: string[] | undefined,
      properties_with_history: string[] | undefined,
      associations: string[] | undefined,
      archived: boolean | undefined,
      id_property: string | undefined
    ) {
      const url = new URL(`https://api.hubapi.com/crm/v3/objects/deals/${deal_id}`)
      if (properties?.length)
        url.searchParams.append("properties", properties.join(","))
      if (properties_with_history?.length)
        url.searchParams.append(
          "propertiesWithHistory",
          properties_with_history.join(",")
        )
      if (associations?.length)
        url.searchParams.append("associations", associations.join(","))
      if (archived) url.searchParams.append("archived", String(archived))
      if (id_property != null && id_property !== "")
        url.searchParams.append("idProperty", id_property)
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 8 days ago