Edits history of script submission #23401 for ' Get Contact (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Contact
     * Retrieve a contact by record ID, with the properties you list.
     */
    export async function main(
      auth: RT.Hubspot,
      contact_id: string,
      properties: string[] | undefined,
      properties_with_history: string[] | undefined
    ) {
      const url = new URL(
        `https://api.hubapi.com/crm/v3/objects/contacts/${contact_id}`
      )
      if (properties?.length)
        url.searchParams.append("properties", properties.join(","))
      if (properties_with_history?.length)
        url.searchParams.append(
          "propertiesWithHistory",
          properties_with_history.join(",")
        )
    
      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 20 days ago