1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Retrieves a list of smart collections |
7 | * Retrieves a list of smart collections. 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 | limit: string | undefined, |
13 | ids: string | undefined, |
14 | since_id: string | undefined, |
15 | title: string | undefined, |
16 | product_id: string | undefined, |
17 | handle: string | undefined, |
18 | updated_at_min: string | undefined, |
19 | updated_at_max: string | undefined, |
20 | published_at_min: string | undefined, |
21 | published_at_max: string | undefined, |
22 | published_status: string | undefined, |
23 | fields: string | undefined |
24 | ) { |
25 | const url = new URL( |
26 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/smart_collections.json` |
27 | ); |
28 | for (const [k, v] of [ |
29 | ["limit", limit], |
30 | ["ids", ids], |
31 | ["since_id", since_id], |
32 | ["title", title], |
33 | ["product_id", product_id], |
34 | ["handle", handle], |
35 | ["updated_at_min", updated_at_min], |
36 | ["updated_at_max", updated_at_max], |
37 | ["published_at_min", published_at_min], |
38 | ["published_at_max", published_at_max], |
39 | ["published_status", published_status], |
40 | ["fields", fields], |
41 | ]) { |
42 | if (v !== undefined && v !== "") { |
43 | url.searchParams.append(k, v); |
44 | } |
45 | } |
46 | const response = await fetch(url, { |
47 | method: "GET", |
48 | headers: { |
49 | "X-Shopify-Access-Token": auth.token, |
50 | }, |
51 | body: undefined, |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|