1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Create a new Page |
7 | * Creates a page. |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | body: { |
13 | page?: { |
14 | body_html?: string; |
15 | published?: boolean; |
16 | title?: string; |
17 | [k: string]: unknown; |
18 | }; |
19 | [k: string]: unknown; |
20 | } |
21 | ) { |
22 | const url = new URL( |
23 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/pages.json` |
24 | ); |
25 |
|
26 | const response = await fetch(url, { |
27 | method: "POST", |
28 | headers: { |
29 | "Content-Type": "application/json", |
30 | "X-Shopify-Access-Token": auth.token, |
31 | }, |
32 | body: JSON.stringify(body), |
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 |
|