//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* List users
* List users, paginated and ordered by their name (alphabetical order).
*/
export async function main(
auth: Gorgias,
page: string | undefined,
per_page: string | undefined,
external_id: string | undefined,
roles: string | undefined,
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/users`);
for (const [k, v] of [
["page", page],
["per_page", per_page],
["external_id", external_id],
["roles", roles],
]) {
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