Create Variant

You can only create one variant for each locale id. If a locale variant already exists, the request is rejected. #### Allowed For * Admins, 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
 * Create Variant
8
 * You can only create one variant for each locale id. If a locale variant already exists, the request is rejected.
9

10
#### Allowed For
11

12
* Admins, Agents
13

14
 */
15
export async function main(auth: Zendesk, dynamic_content_item_id: string) {
16
  const url = new URL(
17
    `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/${dynamic_content_item_id}/variants`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33