0

List surveys

by
Published Oct 17, 2025

List surveys, paginated and ordered by their creation date, with the most recently created first.

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 surveys
9
 * List surveys, paginated and ordered by their creation date, with the most recently created  first.
10

11
 */
12
export async function main(
13
  auth: Gorgias,
14
  page: string | undefined,
15
  per_page: string | undefined,
16
) {
17
  const url = new URL(`https://${auth.domain}.gorgias.com/api/satisfaction-surveys`);
18
  for (const [k, v] of [
19
    ["page", page],
20
    ["per_page", per_page],
21
  ]) {
22
    if (v !== undefined && v !== "" && k !== undefined) {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39