0

List views

by
Published Oct 17, 2025

List all views ordered by their `display_order` attribute, with the smallest position first. Current user variables (`{{current_user...}}`) present in views' filters will be replaced with the information of the user listing views.

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
 * List views
9
 * List all views ordered by their `display_order` attribute, with the smallest position first. Current user variables (`{{current_user...}}`) present in views' filters will be replaced with the information of the user listing views.
10

11
 */
12
export async function main(auth: Gorgias) {
13
  const url = new URL(`https://${auth.domain}.gorgias.com/api/views`);
14

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