Check Host Mapping Validity for an Existing Brand
One script reply has been approved by the moderators Verified

Returns a JSON object determining whether a host mapping is valid for the given brand.

Allowed for

  • Admins
Created by hugo697 844 days ago Picked 1 time
Submitted by hugo697 Typescript (fetch-only)
Verified 298 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Check Host Mapping Validity for an Existing Brand
8
 * Returns a JSON object determining whether a host mapping is valid for the given brand.
9

10
#### Allowed for
11
- Admins
12
 */
13
export async function main(auth: Zendesk, brand_id: string) {
14
  const url = new URL(
15
    `https://${auth.subdomain}.zendesk.com/api/v2/brands/${brand_id}/check_host_mapping`
16
  );
17

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