0

Updates an order risk

by
Published Nov 8, 2023

Updates an order risk Note You cannot modify an order risk that was created by another application.

Script shopify Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Updates an order risk
7
 * Updates an order risk   Note You cannot modify an order risk that was created by another application.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  order_id: string,
13
  risk_id: string,
14
  body: {
15
    risk?: {
16
      cause_cancel?: boolean;
17
      id?: number;
18
      message?: string;
19
      recommendation?: string;
20
      score?: number;
21
      source?: string;
22
      [k: string]: unknown;
23
    };
24
    [k: string]: unknown;
25
  }
26
) {
27
  const url = new URL(
28
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/risks/${risk_id}.json`
29
  );
30

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