Edits history of script submission #23441 for ' Get Owner (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Owner
     * Retrieve one owner by owner ID, or by user ID when `id_property` is userId.
     */
    export async function main(
      auth: RT.Hubspot,
      owner_id: string,
      id_property: "id" | "userId" | undefined
    ) {
      const url = new URL(`https://api.hubapi.com/crm/v3/owners/${owner_id}`)
      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 5 hours ago