1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Receive a count of all DraftOrders |
7 | * Retrieves a count of draft orders |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | since_id: string | undefined, |
13 | status: string | undefined, |
14 | updated_at_max: string | undefined, |
15 | updated_at_min: string | undefined |
16 | ) { |
17 | const url = new URL( |
18 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/draft_orders/count.json` |
19 | ); |
20 | for (const [k, v] of [ |
21 | ["since_id", since_id], |
22 | ["status", status], |
23 | ["updated_at_max", updated_at_max], |
24 | ["updated_at_min", updated_at_min], |
25 | ]) { |
26 | if (v !== undefined && v !== "") { |
27 | url.searchParams.append(k, v); |
28 | } |
29 | } |
30 | const response = await fetch(url, { |
31 | method: "GET", |
32 | headers: { |
33 | "X-Shopify-Access-Token": auth.token, |
34 | }, |
35 | body: undefined, |
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 |
|