0

Create a survey

by
Published Oct 17, 2025

Create a new satisfaction survey. If you don't want the satisfaction survey to be sent by Gorgias set `should_send_datetime` parameter to `null`.

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 survey
9
 * Create a new satisfaction survey. If you don't want the satisfaction survey to be sent by Gorgias set `should_send_datetime` parameter to `null`.
10

11
 */
12
export async function main(
13
  auth: Gorgias,
14
  body: {
15
    body_text?: string;
16
    created_datetime?: string;
17
    customer_id: number;
18
    meta?: {};
19
    score?: number;
20
    scored_datetime?: string;
21
    sent_datetime?: string;
22
    should_send_datetime?: string;
23
    ticket_id: number;
24
  },
25
) {
26
  const url = new URL(`https://${auth.domain}.gorgias.com/api/satisfaction-surveys`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42