//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* List view's items
* List view's items, paginated, and ordered by the attribute specified in the data of view.
*/
export async function main(
auth: Gorgias,
view_id: string,
ignored_item: string | undefined,
cursor: string | undefined,
direction: "prev" | "next" | undefined,
limit: string | undefined,
) {
const url = new URL(
`https://${auth.domain}.gorgias.com/api/views/${view_id}/items`,
);
for (const [k, v] of [
["ignored_item", ignored_item],
["cursor", cursor],
["direction", direction],
["limit", limit],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
},
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