0

List Owners

by
Published 20 days ago

List the account's owners (users that can be assigned to records), optionally filtered by email.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 21 days ago
1
//native
2

3
/**
4
 * List Owners
5
 * List the account's owners (users that can be assigned to records), optionally filtered by email.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  email: string | undefined,
10
  limit: number | undefined,
11
  after: string | undefined,
12
  archived: boolean | undefined
13
) {
14
  const url = new URL(`https://api.hubapi.com/crm/v3/owners`)
15
  if (email != null && email !== "") url.searchParams.append("email", email)
16
  if (limit != null) url.searchParams.append("limit", String(limit))
17
  if (after != null && after !== "") url.searchParams.append("after", after)
18
  if (archived) url.searchParams.append("archived", String(archived))
19

20
  const response = await fetch(url, {
21
    headers: {
22
      Authorization: `Bearer ${auth.token}`,
23
      Accept: "application/json",
24
    },
25
  })
26

27
  if (!response.ok) {
28
    throw new Error(`${response.status} ${await response.text()}`)
29
  }
30

31
  return await response.json()
32
}
33