1 | |
2 | type Tomorrow = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update an Insight |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Tomorrow, |
11 | insightId: string, |
12 | body: { |
13 | name?: string; |
14 | rules?: string; |
15 | conditions?: string; |
16 | tags?: string[]; |
17 | severity?: string; |
18 | description?: string; |
19 | }, |
20 | Accept_Encoding?: string, |
21 | ) { |
22 | const url = new URL(`https://api.tomorrow.io/v4/insights/${insightId}`); |
23 |
|
24 | const response = await fetch(url, { |
25 | method: "PUT", |
26 | headers: { |
27 | ...(Accept_Encoding ? { "Accept-Encoding": Accept_Encoding } : {}), |
28 | "Content-Type": "application/json", |
29 | ApiKey: auth.apiKey, |
30 | }, |
31 | body: JSON.stringify(body), |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.json(); |
38 | } |
39 |
|