Create a new ResourceFeedback

Creates shop resource feedback.

Script shopify Verified

by hugo697 ยท 11/8/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Create a new ResourceFeedback
7
 * Creates shop resource feedback.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  body: {
13
    resource_feedback?: {
14
      feedback_generated_at?: string;
15
      state?: string;
16
      [k: string]: unknown;
17
    };
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/resource_feedback.json`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      "X-Shopify-Access-Token": auth.token,
30
    },
31
    body: JSON.stringify(body),
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