1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Retrieves a list of webhooks |
7 | * Retrieves a list of webhooks. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. To learn more, see Making requests to paginated REST Admin API endpoints. |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | address: string | undefined, |
13 | created_at_max: string | undefined, |
14 | created_at_min: string | undefined, |
15 | fields: string | undefined, |
16 | limit: string | undefined, |
17 | since_id: string | undefined, |
18 | topic: string | undefined, |
19 | updated_at_min: string | undefined, |
20 | updated_at_max: string | undefined |
21 | ) { |
22 | const url = new URL( |
23 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/webhooks.json` |
24 | ); |
25 | for (const [k, v] of [ |
26 | ["address", address], |
27 | ["created_at_max", created_at_max], |
28 | ["created_at_min", created_at_min], |
29 | ["fields", fields], |
30 | ["limit", limit], |
31 | ["since_id", since_id], |
32 | ["topic", topic], |
33 | ["updated_at_min", updated_at_min], |
34 | ["updated_at_max", updated_at_max], |
35 | ]) { |
36 | if (v !== undefined && v !== "") { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "GET", |
42 | headers: { |
43 | "X-Shopify-Access-Token": auth.token, |
44 | }, |
45 | body: undefined, |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|