1 | |
2 | type Tomorrow = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update a Location |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Tomorrow, |
11 | locationId: string, |
12 | Accept_Encoding: string, |
13 | body: { name?: string; direction?: number }, |
14 | ) { |
15 | const url = new URL(`https://api.tomorrow.io/v4/locations/${locationId}`); |
16 |
|
17 | const response = await fetch(url, { |
18 | method: "PUT", |
19 | headers: { |
20 | "Accept-Encoding": Accept_Encoding, |
21 | "Content-Type": "application/json", |
22 | ApiKey: auth.apiKey, |
23 | }, |
24 | body: JSON.stringify(body), |
25 | }); |
26 | if (!response.ok) { |
27 | const text = await response.text(); |
28 | throw new Error(`${response.status} ${text}`); |
29 | } |
30 | return await response.json(); |
31 | } |
32 |
|