1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Associate territories to user |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | user: string, |
12 | body: { |
13 | territories: { |
14 | id: string; |
15 | Manager: { Name: string; id: string }; |
16 | Reporting_To: { Name: string; id: string }; |
17 | Name: string; |
18 | }[]; |
19 | }, |
20 | ) { |
21 | const url = new URL(`https://zohoapis.com/crm/v8/users/${user}/territories`); |
22 |
|
23 | const response = await fetch(url, { |
24 | method: "PUT", |
25 | headers: { |
26 | "Content-Type": "application/json", |
27 | Authorization: "Zoho-oauthtoken " + auth.token, |
28 | }, |
29 | body: JSON.stringify(body), |
30 | }); |
31 | if (!response.ok) { |
32 | const text = await response.text(); |
33 | throw new Error(`${response.status} ${text}`); |
34 | } |
35 | return await response.json(); |
36 | } |
37 |
|