List Memberships

Returns a list of organization memberships for the account, user or organization in question. **Note**: When returning organization memberships for a user, organization memberships are sorted with the default organization first, and then by organization name. #### Pagination * Cursor pagination (recommended) * Offset pagination See Pagination. Returns a maximum of 100 records per page. #### Allowed For - Agents - End users

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * List Memberships
8
 * Returns a list of organization memberships for the account, user or organization in question.
9

10
**Note**: When returning organization memberships for a user, organization memberships are sorted with the default organization first, and then by organization name.
11

12
#### Pagination
13

14
* Cursor pagination (recommended)
15
* Offset pagination
16

17
See Pagination.
18

19
Returns a maximum of 100 records per page.
20

21
#### Allowed For
22

23
- Agents
24
- End users
25

26
 */
27
export async function main(auth: Zendesk) {
28
  const url = new URL(
29
    `https://${auth.subdomain}.zendesk.com/api/v2/organization_memberships`
30
  );
31

32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45