1 | |
2 |
|
3 | |
4 | * Update Organization |
5 | * Update an organization by id; only the fields you fill are changed. `domain_names` and `tags` replace the existing lists. Set any other field through `fields`, e.g. `{ "organization_fields": { "tier": "gold" } }`. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Zendesk, |
9 | organization_id: number, |
10 | name: string | undefined, |
11 | domain_names: string[] | undefined, |
12 | details: string | undefined, |
13 | notes: string | undefined, |
14 | external_id: string | undefined, |
15 | tags: string[] | undefined, |
16 | fields: { [key: string]: any } | undefined |
17 | ) { |
18 | const organization = { |
19 | ...fields, |
20 | name: name || undefined, |
21 | domain_names: domain_names?.length ? domain_names : undefined, |
22 | details: details || undefined, |
23 | notes: notes || undefined, |
24 | external_id: external_id || undefined, |
25 | tags: tags?.length ? tags : undefined, |
26 | } |
27 |
|
28 | const response = await fetch( |
29 | `https://${auth.subdomain}.zendesk.com/api/v2/organizations/${organization_id}`, |
30 | { |
31 | method: "PUT", |
32 | headers: { |
33 | Authorization: auth.token |
34 | ? `Bearer ${auth.token}` |
35 | : `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
36 | "Content-Type": "application/json", |
37 | Accept: "application/json", |
38 | }, |
39 | body: JSON.stringify({ organization }), |
40 | } |
41 | ) |
42 |
|
43 | if (!response.ok) { |
44 | throw new Error(`${response.status} ${await response.text()}`) |
45 | } |
46 |
|
47 | return await response.json() |
48 | } |
49 |
|