//native
type Square = {
token: string;
};
/**
* ListCustomers
* Lists customer profiles associated with a Square account.
Under normal operating conditions, newly created or updated customer profiles become available
for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated
profiles can take closer to one minute or longer, especially during network incidents and outages.
*/
export async function main(
auth: Square,
cursor: string | undefined,
limit: string | undefined,
sort_field: "DEFAULT" | "CREATED_AT" | undefined,
sort_order: "DESC" | "ASC" | undefined,
count: string | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/customers`);
for (const [k, v] of [
["cursor", cursor],
["limit", limit],
["sort_field", sort_field],
["sort_order", sort_order],
["count", count],
]) {
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