Updates a comment of an article

Updates a comment of an article

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
 * Updates a comment of an article
7
 * Updates a comment of an article
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  comment_id: string,
13
  body: {
14
    comment?: {
15
      author?: string;
16
      body?: string;
17
      email?: string;
18
      id?: number;
19
      published_at?: string;
20
      [k: string]: unknown;
21
    };
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/comments/${comment_id}.json`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "PUT",
31
    headers: {
32
      "Content-Type": "application/json",
33
      "X-Shopify-Access-Token": auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43