0
Create Trial Account
One script reply has been approved by the moderators Verified

Create Trial Account

Created by hugo697 639 days ago Viewed 22523 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 639 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Create Trial Account
8
 * Create Trial Account
9
 */
10
export async function main(auth: Zendesk) {
11
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/accounts`);
12

13
  const response = await fetch(url, {
14
    method: "POST",
15
    headers: {
16
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
17
    },
18
    body: undefined,
19
  });
20
  if (!response.ok) {
21
    const text = await response.text();
22
    throw new Error(`${response.status} ${text}`);
23
  }
24
  return await response.json();
25
}
26