//native
type Square = {
token: string;
};
/**
* SearchInvoices
* Searches for invoices from a location specified in
the filter. You can optionally specify customers in the filter for whom to
retrieve invoices. In the current implementation, you can only specify one location and
optionally one customer.
The response is paginated. If truncated, the response includes a `cursor`
that you use in a subsequent request to retrieve the next set of invoices.
*/
export async function main(
auth: Square,
body: {
query: {
filter: { location_ids: string[]; customer_ids?: string[] };
sort?: { field: "INVOICE_SORT_DATE"; order?: "DESC" | "ASC" };
};
limit?: number;
cursor?: string;
},
) {
const url = new URL(`https://connect.squareup.com/v2/invoices/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