1 | |
2 | type Webflow = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Webflow, |
8 | site_id: string, |
9 | product_id: string, |
10 | body: { |
11 | publishStatus?: 'staging' | 'live' |
12 | product?: { |
13 | id?: string |
14 | cmsLocaleId?: string |
15 | lastPublished?: string |
16 | lastUpdated?: string |
17 | createdOn?: string |
18 | isArchived?: false | true |
19 | isDraft?: false | true |
20 | fieldData?: { |
21 | name?: string |
22 | slug?: string |
23 | description?: string |
24 | shippable?: false | true |
25 | 'sku-properties'?: { |
26 | id: string |
27 | name: string |
28 | enum: { id: string; name: string; slug: string }[] |
29 | }[] |
30 | categories?: string[] |
31 | 'tax-category'?: |
32 | | 'standard-taxable' |
33 | | 'standard-exempt' |
34 | | 'books-religious' |
35 | | 'books-textbook' |
36 | | 'clothing' |
37 | | 'clothing-swimwear' |
38 | | 'digital-goods' |
39 | | 'digital-service' |
40 | | 'drugs-non-prescription' |
41 | | 'drugs-prescription' |
42 | | 'food-bottled-water' |
43 | | 'food-candy' |
44 | | 'food-groceries' |
45 | | 'food-prepared' |
46 | | 'food-soda' |
47 | | 'food-supplements' |
48 | | 'magazine-individual' |
49 | | 'magazine-subscription' |
50 | | 'service-admission' |
51 | | 'service-advertising' |
52 | | 'service-dry-cleaning' |
53 | | 'service-hairdressing' |
54 | | 'service-installation' |
55 | | 'service-miscellaneous' |
56 | | 'service-parking' |
57 | | 'service-printing' |
58 | | 'service-professional' |
59 | | 'service-repair' |
60 | | 'service-training' |
61 | 'default-sku'?: string |
62 | 'ec-product-type'?: |
63 | | 'ff42fee0113744f693a764e3431a9cc2' |
64 | | 'f22027db68002190aef89a4a2b7ac8a1' |
65 | | 'c599e43b1a1c34d5a323aedf75d3adf6' |
66 | | 'b6ccc1830db4b1babeb06a9ac5f6dd76' |
67 | } |
68 | } |
69 | sku?: { |
70 | id?: string |
71 | cmsLocaleId?: string |
72 | lastPublished?: string |
73 | lastUpdated?: string |
74 | createdOn?: string |
75 | fieldData?: { |
76 | 'sku-values'?: {} |
77 | name: string |
78 | slug: string |
79 | price: { value?: number; unit?: string } |
80 | 'compare-at-price'?: { value?: number; unit?: string } |
81 | 'ec-sku-billing-method'?: 'one-time' | 'subscription' |
82 | 'ec-sku-subscription-plan'?: { |
83 | interval?: 'day' | 'week' | 'month' | 'year' |
84 | frequency?: number |
85 | trial?: number |
86 | plans?: { |
87 | platform?: 'stripe' |
88 | id?: string |
89 | status?: 'active' | 'inactive' | 'canceled' |
90 | }[] |
91 | } |
92 | 'track-inventory'?: false | true |
93 | quantity?: number |
94 | } |
95 | } |
96 | } |
97 | ) { |
98 | const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/products/${product_id}`) |
99 |
|
100 | const response = await fetch(url, { |
101 | method: 'PATCH', |
102 | headers: { |
103 | 'Content-Type': 'application/json', |
104 | Authorization: 'Bearer ' + auth.token |
105 | }, |
106 | body: JSON.stringify(body) |
107 | }) |
108 |
|
109 | if (!response.ok) { |
110 | const text = await response.text() |
111 | throw new Error(`${response.status} ${text}`) |
112 | } |
113 |
|
114 | return await response.json() |
115 | } |
116 |
|