Request User Create

Sends the owner a reminder email to update their subscription so more agents can be created. #### Allowed For * Agents

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
 * Request User Create
8
 * Sends the owner a reminder email to update their subscription so more agents can be created.
9

10
#### Allowed For
11

12
* Agents
13

14
 */
15
export async function main(
16
  auth: Zendesk,
17
  body: {
18
    user?: {
19
      custom_role_id?: string;
20
      email?: string;
21
      external_id?: string;
22
      identities?: { type?: string; value?: string; [k: string]: unknown }[];
23
      name?: string;
24
      organization?: { name?: string; [k: string]: unknown };
25
      organization_id?: string;
26
      role?: string;
27
      [k: string]: unknown;
28
    };
29
    [k: string]: unknown;
30
  }
31
) {
32
  const url = new URL(
33
    `https://${auth.subdomain}.zendesk.com/api/v2/users/request_create`
34
  );
35

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