//native
type Square = {
token: string;
};
/**
* ListInvoices
* Returns a list of invoices for a given location. 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,
location_id: string | undefined,
cursor: string | undefined,
limit: string | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/invoices`);
for (const [k, v] of [
["location_id", location_id],
["cursor", cursor],
["limit", limit],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago