0

Create a view

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
 * Create a view
9
 *
10
 */
11
export async function main(
12
  auth: Gorgias,
13
  body: {
14
    category?: string;
15
    deactivated_datetime?: string;
16
    decoration?: { emoji?: string };
17
    display_order?: number;
18
    fields?:
19
      | "details"
20
      | "tags"
21
      | "customer"
22
      | "last_message"
23
      | "name"
24
      | "email"
25
      | "created"
26
      | "updated"
27
      | "assignee"
28
      | "assignee_team"
29
      | "channel"
30
      | "closed"
31
      | "language"
32
      | "last_received_message"
33
      | "integrations"
34
      | "snooze"
35
      | "status"
36
      | "subject"[];
37
    filters?: string;
38
    filters_ast?: {};
39
    name?: string;
40
    order_by?: string;
41
    order_dir?: "asc" | "desc";
42
    shared_with_teams?: number[];
43
    shared_with_users?: number[];
44
    slug: string;
45
    type?: "ticket-list";
46
    visibility?: "public" | "shared" | "private";
47
  },
48
) {
49
  const url = new URL(`https://${auth.domain}.gorgias.com/api/views`);
50

51
  const response = await fetch(url, {
52
    method: "POST",
53
    headers: {
54
      "Content-Type": "application/json",
55
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
56
    },
57
    body: JSON.stringify(body),
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65