0

SearchCatalogItems

by
Published Oct 17, 2025

Searches for catalog items or item variations by matching supported search attribute values, including custom attribute values, against one or more of the specified query filters.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * SearchCatalogItems
7
 * Searches for catalog items or item variations by matching supported search attribute values, including
8
custom attribute values, against one or more of the specified query filters.
9
 */
10
export async function main(
11
  auth: Square,
12
  body: {
13
    text_filter?: string;
14
    category_ids?: string[];
15
    stock_levels?: "OUT" | "LOW"[];
16
    enabled_location_ids?: string[];
17
    cursor?: string;
18
    limit?: number;
19
    sort_order?: "DESC" | "ASC";
20
    product_types?:
21
      | "REGULAR"
22
      | "GIFT_CARD"
23
      | "APPOINTMENTS_SERVICE"
24
      | "FOOD_AND_BEV"
25
      | "EVENT"
26
      | "DIGITAL"
27
      | "DONATION"
28
      | "LEGACY_SQUARE_ONLINE_SERVICE"
29
      | "LEGACY_SQUARE_ONLINE_MEMBERSHIP"[];
30
    custom_attribute_filters?: {
31
      custom_attribute_definition_id?: string;
32
      key?: string;
33
      string_filter?: string;
34
      number_filter?: { min?: string; max?: string };
35
      selection_uids_filter?: string[];
36
      bool_filter?: false | true;
37
    }[];
38
    archived_state?:
39
      | "ARCHIVED_STATE_NOT_ARCHIVED"
40
      | "ARCHIVED_STATE_ARCHIVED"
41
      | "ARCHIVED_STATE_ALL";
42
  },
43
) {
44
  const url = new URL(
45
    `https://connect.squareup.com/v2/catalog/search-catalog-items`,
46
  );
47

48
  const response = await fetch(url, {
49
    method: "POST",
50
    headers: {
51
      "Content-Type": "application/json",
52
      Authorization: "Bearer " + auth.token,
53
    },
54
    body: JSON.stringify(body),
55
  });
56
  if (!response.ok) {
57
    const text = await response.text();
58
    throw new Error(`${response.status} ${text}`);
59
  }
60
  return await response.json();
61
}
62