//native
type Square = {
token: string;
};
/**
* SearchVendors
* Searches for vendors using a filter against supported [Vendor]($m/Vendor) properties and a supported sorter.
*/
export async function main(
auth: Square,
body: {
filter?: { name?: string[]; status?: "ACTIVE" | "INACTIVE"[] };
sort?: { field?: "NAME" | "CREATED_AT"; order?: "DESC" | "ASC" };
cursor?: string;
},
) {
const url = new URL(`https://connect.squareup.com/v2/vendors/search`);
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