0

Retrieve Climate Normals

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 Climate Normals
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
    startDate: string;
17
    endDate: string;
18
    units?: string;
19
  },
20
) {
21
  const url = new URL(`https://api.tomorrow.io/v4/historical/normals`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Accept-Encoding": Accept_Encoding,
27
      "Content-Type": "application/json",
28
      ApiKey: auth.apiKey,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38