0

SearchEvents

by
Published Oct 17, 2025

Search for Square API events that occur within a 28-day timeframe.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * SearchEvents
7
 * Search for Square API events that occur within a 28-day timeframe.
8
 */
9
export async function main(
10
  auth: Square,
11
  body: {
12
    cursor?: string;
13
    limit?: number;
14
    query?: {
15
      filter?: {
16
        event_types?: string[];
17
        merchant_ids?: string[];
18
        location_ids?: string[];
19
        created_at?: { start_at?: string; end_at?: string };
20
      };
21
      sort?: { field?: "DEFAULT"; order?: "DESC" | "ASC" };
22
    };
23
  },
24
) {
25
  const url = new URL(`https://connect.squareup.com/v2/events`);
26

27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41