1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Creates a new script tag |
7 | * Creates a new script tag |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | body: { |
13 | script_tag?: { body?: string; [k: string]: unknown }; |
14 | [k: string]: unknown; |
15 | } |
16 | ) { |
17 | const url = new URL( |
18 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/script_tags.json` |
19 | ); |
20 |
|
21 | const response = await fetch(url, { |
22 | method: "POST", |
23 | headers: { |
24 | "Content-Type": "application/json", |
25 | "X-Shopify-Access-Token": auth.token, |
26 | }, |
27 | body: JSON.stringify(body), |
28 | }); |
29 | if (!response.ok) { |
30 | const text = await response.text(); |
31 | throw new Error(`${response.status} ${text}`); |
32 | } |
33 | return await response.json(); |
34 | } |
35 |
|