0

Get Owner

by
Published today

Retrieve one owner by owner ID, or by user ID when `id_property` is userId.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Get Owner
5
 * Retrieve one owner by owner ID, or by user ID when `id_property` is userId.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  owner_id: string,
10
  id_property: "id" | "userId" | undefined
11
) {
12
  const url = new URL(`https://api.hubapi.com/crm/v3/owners/${owner_id}`)
13
  if (id_property != null && id_property !== "")
14
    url.searchParams.append("idProperty", id_property)
15

16
  const response = await fetch(url, {
17
    headers: {
18
      Authorization: `Bearer ${auth.token}`,
19
      Accept: "application/json",
20
    },
21
  })
22

23
  if (!response.ok) {
24
    throw new Error(`${response.status} ${await response.text()}`)
25
  }
26

27
  return await response.json()
28
}
29