//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* List macros
*
*/
export async function main(
auth: Gorgias,
search: string | undefined,
cursor: string | undefined,
order_dir: "asc" | "desc" | undefined,
ticket_id: string | undefined,
page: string | undefined,
message_id: string | undefined,
per_page: string | undefined,
limit: string | undefined,
order_by:
| "name"
| "created_datetime"
| "updated_datetime"
| "usage"
| "relevance"
| "name:asc"
| "created_datetime:desc"
| "updated_datetime:desc"
| "usage:desc"
| "relevance:desc"
| undefined,
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/macros`);
for (const [k, v] of [
["search", search],
["cursor", cursor],
["order_dir", order_dir],
["ticket_id", ticket_id],
["page", page],
["message_id", message_id],
["per_page", per_page],
["limit", limit],
["order_by", order_by],
]) {
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