1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Receive a list of all Product Images |
7 | * Get all product images |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | product_id: string, |
13 | since_id: string | undefined, |
14 | fields: string | undefined |
15 | ) { |
16 | const url = new URL( |
17 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/products/${product_id}/images.json` |
18 | ); |
19 | for (const [k, v] of [ |
20 | ["since_id", since_id], |
21 | ["fields", fields], |
22 | ]) { |
23 | if (v !== undefined && v !== "") { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "GET", |
29 | headers: { |
30 | "X-Shopify-Access-Token": auth.token, |
31 | }, |
32 | body: undefined, |
33 | }); |
34 | if (!response.ok) { |
35 | const text = await response.text(); |
36 | throw new Error(`${response.status} ${text}`); |
37 | } |
38 | return await response.json(); |
39 | } |
40 |
|