1 | |
2 | type Square = { |
3 | token: string; |
4 | }; |
5 | |
6 | * SearchCatalogObjects |
7 | * Searches for [CatalogObject]($m/CatalogObject) of any type by matching supported search attribute values, |
8 | excluding custom attribute values on items or item variations, against one or more of the specified query filters. |
9 | */ |
10 | export async function main( |
11 | auth: Square, |
12 | body: { |
13 | cursor?: string; |
14 | object_types?: |
15 | | "ITEM" |
16 | | "IMAGE" |
17 | | "CATEGORY" |
18 | | "ITEM_VARIATION" |
19 | | "TAX" |
20 | | "DISCOUNT" |
21 | | "MODIFIER_LIST" |
22 | | "MODIFIER" |
23 | | "PRICING_RULE" |
24 | | "PRODUCT_SET" |
25 | | "TIME_PERIOD" |
26 | | "MEASUREMENT_UNIT" |
27 | | "SUBSCRIPTION_PLAN_VARIATION" |
28 | | "ITEM_OPTION" |
29 | | "ITEM_OPTION_VAL" |
30 | | "CUSTOM_ATTRIBUTE_DEFINITION" |
31 | | "QUICK_AMOUNTS_SETTINGS" |
32 | | "SUBSCRIPTION_PLAN" |
33 | | "AVAILABILITY_PERIOD"[]; |
34 | include_deleted_objects?: false | true; |
35 | include_related_objects?: false | true; |
36 | begin_time?: string; |
37 | query?: { |
38 | sorted_attribute_query?: { |
39 | attribute_name: string; |
40 | initial_attribute_value?: string; |
41 | sort_order?: "DESC" | "ASC"; |
42 | }; |
43 | exact_query?: { attribute_name: string; attribute_value: string }; |
44 | set_query?: { attribute_name: string; attribute_values: string[] }; |
45 | prefix_query?: { attribute_name: string; attribute_prefix: string }; |
46 | range_query?: { |
47 | attribute_name: string; |
48 | attribute_min_value?: number; |
49 | attribute_max_value?: number; |
50 | }; |
51 | text_query?: { keywords: string[] }; |
52 | items_for_tax_query?: { tax_ids: string[] }; |
53 | items_for_modifier_list_query?: { modifier_list_ids: string[] }; |
54 | items_for_item_options_query?: { item_option_ids?: string[] }; |
55 | item_variations_for_item_option_values_query?: { |
56 | item_option_value_ids?: string[]; |
57 | }; |
58 | }; |
59 | limit?: number; |
60 | include_category_path_to_root?: false | true; |
61 | }, |
62 | ) { |
63 | const url = new URL(`https://connect.squareup.com/v2/catalog/search`); |
64 |
|
65 | const response = await fetch(url, { |
66 | method: "POST", |
67 | headers: { |
68 | "Content-Type": "application/json", |
69 | Authorization: "Bearer " + auth.token, |
70 | }, |
71 | body: JSON.stringify(body), |
72 | }); |
73 | if (!response.ok) { |
74 | const text = await response.text(); |
75 | throw new Error(`${response.status} ${text}`); |
76 | } |
77 | return await response.json(); |
78 | } |
79 |
|