//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* List messages
* List all messages of a ticket, ordered by their sending date, with the oldest messages first.
*/
export async function main(auth: Gorgias, ticket_id: string) {
const url = new URL(
`https://${auth.domain}.gorgias.com/api/tickets/${ticket_id}/messages`,
);
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