0

Retrieve Historical Weather

by
Published Oct 17, 2025
Script tomorrow Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Tomorrow = {
3
  apiKey: string;
4
};
5
/**
6
 * Retrieve Historical Weather
7
 *
8
 */
9
export async function main(
10
  auth: Tomorrow,
11
  Accept_Encoding: string,
12
  body: {
13
    location: string;
14
    fields: string[];
15
    timesteps: string[];
16
    startTime: string;
17
    endTime: string;
18
    units?: string;
19
    timezone?: string;
20
  },
21
) {
22
  const url = new URL(`https://api.tomorrow.io/v4/historical`);
23

24
  const response = await fetch(url, {
25
    method: "POST",
26
    headers: {
27
      "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