//native
type Square = {
token: string;
};
/**
* ListGiftCardActivities
* Lists gift card activities. By default, you get gift card activities for all
gift cards in the seller's account. You can optionally specify query parameters to
filter the list. For example, you can get a list of gift card activities for a gift card,
for all gift cards in a specific region, or for activities within a time window.
*/
export async function main(
auth: Square,
gift_card_id: string | undefined,
type: string | undefined,
location_id: string | undefined,
begin_time: string | undefined,
end_time: string | undefined,
limit: string | undefined,
cursor: string | undefined,
sort_order: string | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/gift-cards/activities`);
for (const [k, v] of [
["gift_card_id", gift_card_id],
["type", type],
["location_id", location_id],
["begin_time", begin_time],
["end_time", end_time],
["limit", limit],
["cursor", cursor],
["sort_order", sort_order],
]) {
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