0

Delete a message

by
Published Oct 17, 2025
Script gorgias Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gorgias = {
3
  username: string;
4
  apiKey: string;
5
  domain: string;
6
};
7
/**
8
 * Delete a message
9
 *
10
 */
11
export async function main(auth: Gorgias, ticket_id: string, id: string) {
12
  const url = new URL(
13
    `https://${auth.domain}.gorgias.com/api/tickets/${ticket_id}/messages/${id}/`,
14
  );
15

16
  const response = await fetch(url, {
17
    method: "DELETE",
18
    headers: {
19
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.text();
28
}
29