1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Updates a report |
7 | * Updates a report |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | report_id: string, |
13 | body: { |
14 | report?: { |
15 | id?: number; |
16 | name?: string; |
17 | shopify_ql?: string; |
18 | [k: string]: unknown; |
19 | }; |
20 | [k: string]: unknown; |
21 | } |
22 | ) { |
23 | const url = new URL( |
24 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/reports/${report_id}.json` |
25 | ); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "PUT", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | "X-Shopify-Access-Token": auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|