//native
type Square = {
token: string;
};
/**
* SearchCatalogItems
* 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.
*/
export async function main(
auth: Square,
body: {
text_filter?: string;
category_ids?: string[];
stock_levels?: "OUT" | "LOW"[];
enabled_location_ids?: string[];
cursor?: string;
limit?: number;
sort_order?: "DESC" | "ASC";
product_types?:
| "REGULAR"
| "GIFT_CARD"
| "APPOINTMENTS_SERVICE"
| "FOOD_AND_BEV"
| "EVENT"
| "DIGITAL"
| "DONATION"
| "LEGACY_SQUARE_ONLINE_SERVICE"
| "LEGACY_SQUARE_ONLINE_MEMBERSHIP"[];
custom_attribute_filters?: {
custom_attribute_definition_id?: string;
key?: string;
string_filter?: string;
number_filter?: { min?: string; max?: string };
selection_uids_filter?: string[];
bool_filter?: false | true;
}[];
archived_state?:
| "ARCHIVED_STATE_NOT_ARCHIVED"
| "ARCHIVED_STATE_ARCHIVED"
| "ARCHIVED_STATE_ALL";
},
) {
const url = new URL(
`https://connect.squareup.com/v2/catalog/search-catalog-items`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago