Update a Brand

Returns an updated brand. #### Allowed for * Admins #### Updating a Brand's Image A brand image can be updated by uploading a local file using the update brand endpoint. See the **Using curl** sections below for more information.

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 a Brand
8
 * Returns an updated brand.
9

10
#### Allowed for
11
* Admins
12

13
#### Updating a Brand's Image
14
A brand image can be updated by uploading a local file using the update brand endpoint. See the **Using curl** sections below for more information.
15
 */
16
export async function main(
17
  auth: Zendesk,
18
  brand_id: string,
19
  body: {
20
    brand?: {
21
      active?: string;
22
      brand_url?: string;
23
      created_at?: string;
24
      default?: string;
25
      has_help_center?: string;
26
      help_center_state?: string;
27
      host_mapping?: string;
28
      id?: string;
29
      is_deleted?: string;
30
      logo?: {
31
        content_type?: string;
32
        content_url?: string;
33
        deleted?: string;
34
        file_name?: string;
35
        height?: string;
36
        id?: string;
37
        inline?: string;
38
        malware_access_override?: string;
39
        malware_scan_result?: string;
40
        mapped_content_url?: string;
41
        size?: string;
42
        thumbnails?: {
43
          content_type?: string;
44
          content_url?: string;
45
          deleted?: string;
46
          file_name?: string;
47
          height?: string;
48
          id?: string;
49
          inline?: string;
50
          malware_access_override?: string;
51
          malware_scan_result?: string;
52
          mapped_content_url?: string;
53
          size?: string;
54
          url?: string;
55
          width?: string;
56
          [k: string]: unknown;
57
        }[];
58
        url?: string;
59
        width?: string;
60
        [k: string]: unknown;
61
      };
62
      name?: string;
63
      signature_template?: string;
64
      subdomain?: string;
65
      ticket_form_ids?: string;
66
      updated_at?: string;
67
      url?: string;
68
      [k: string]: unknown;
69
    };
70
    [k: string]: unknown;
71
  }
72
) {
73
  const url = new URL(
74
    `https://${auth.subdomain}.zendesk.com/api/v2/brands/${brand_id}`
75
  );
76

77
  const response = await fetch(url, {
78
    method: "PUT",
79
    headers: {
80
      "Content-Type": "application/json",
81
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
82
    },
83
    body: JSON.stringify(body),
84
  });
85
  if (!response.ok) {
86
    const text = await response.text();
87
    throw new Error(`${response.status} ${text}`);
88
  }
89
  return await response.json();
90
}
91