1 | |
2 | type Tomorrow = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Retrieve Timelines |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Tomorrow, |
11 | Accept_Encoding: string, |
12 | body: { |
13 | location?: string; |
14 | fields: string[]; |
15 | units?: string; |
16 | timesteps?: string[]; |
17 | startTime?: string; |
18 | endTime?: string; |
19 | timezone?: string; |
20 | dailyStartHour?: number; |
21 | }, |
22 | ) { |
23 | const url = new URL(`https://api.tomorrow.io/v4/timelines`); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "POST", |
27 | headers: { |
28 | "Accept-Encoding": Accept_Encoding, |
29 | "Content-Type": "application/json", |
30 | ApiKey: auth.apiKey, |
31 | }, |
32 | body: JSON.stringify(body), |
33 | }); |
34 | if (!response.ok) { |
35 | const text = await response.text(); |
36 | throw new Error(`${response.status} ${text}`); |
37 | } |
38 | return await response.json(); |
39 | } |
40 |
|