0

Custom Vector Events API

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
 * Custom Vector Events API
7
 *
8
 */
9
export async function main(
10
  auth: Tomorrow,
11
  feedName: string = "sample",
12
  format: string = "geojson",
13
  body: { timeRange?: {}; geofence?: {}; attributes?: {} },
14
  Accept_Encoding?: string,
15
) {
16
  const url = new URL(
17
    `https://api.tomorrow.io/v4/events-custom/${feedName}.${format}`,
18
  );
19

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