Create Organization Subscription

#### Allowed For: * Agents * End users End users can only subscribe to shared organizations in which they're members.

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
 * Create Organization Subscription
8
 * #### Allowed For:
9

10
* Agents
11
* End users
12

13
End users can only subscribe to shared organizations in which they're members.
14
 */
15
export async function main(
16
  auth: Zendesk,
17
  body: {
18
    organization_subscription?: {
19
      organization_id?: string;
20
      user_id?: string;
21
      [k: string]: unknown;
22
    };
23
    [k: string]: unknown;
24
  }
25
) {
26
  const url = new URL(
27
    `https://${auth.subdomain}.zendesk.com/api/v2/organization_subscriptions`
28
  );
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44