1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Updates a customer |
7 | * Updates a customer. |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | customer_id: string, |
13 | body: { |
14 | customer?: { |
15 | id?: number; |
16 | metafields?: { |
17 | key?: string; |
18 | namespace?: string; |
19 | value?: string; |
20 | value_type?: string; |
21 | [k: string]: unknown; |
22 | }[]; |
23 | [k: string]: unknown; |
24 | }; |
25 | [k: string]: unknown; |
26 | } |
27 | ) { |
28 | const url = new URL( |
29 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/customers/${customer_id}.json` |
30 | ); |
31 |
|
32 | const response = await fetch(url, { |
33 | method: "PUT", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | "X-Shopify-Access-Token": auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|