1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Retrieves a list of tender transactions |
7 | * Retrieves a list of tender transactions. 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 | since_id: string | undefined, |
14 | processed_at_min: string | undefined, |
15 | processed_at_max: string | undefined, |
16 | processed_at: string | undefined, |
17 | order: string | undefined |
18 | ) { |
19 | const url = new URL( |
20 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/tender_transactions.json` |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["limit", limit], |
24 | ["since_id", since_id], |
25 | ["processed_at_min", processed_at_min], |
26 | ["processed_at_max", processed_at_max], |
27 | ["processed_at", processed_at], |
28 | ["order", order], |
29 | ]) { |
30 | if (v !== undefined && v !== "") { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "GET", |
36 | headers: { |
37 | "X-Shopify-Access-Token": auth.token, |
38 | }, |
39 | body: undefined, |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|