Update Variant

Updates the specified variant. You don't need to include all the properties. If you just want to update content, for example, then include just that. You can't switch the active state of the default variant of an item. Similarly, you can't switch the default to false if the variant is the default. You must make another variant default instead. #### 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
 * Update Variant
8
 * Updates the specified variant. You don't need to include all the properties. If you just want to update content, for example, then include just that.
9

10
You can't switch the active state of the default variant of an item. Similarly, you can't switch the default to false if the variant is the default. You must make another variant default instead.
11

12
#### Allowed For
13

14
* Admins, Agents
15

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

26
  const response = await fetch(url, {
27
    method: "PUT",
28
    headers: {
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39