//native
type Webflow = {
token: string
}
export async function main(
auth: Webflow,
site_id: string,
product_id: string,
body: {
publishStatus?: 'staging' | 'live'
skus: {
id?: string
cmsLocaleId?: string
lastPublished?: string
lastUpdated?: string
createdOn?: string
fieldData?: {
'sku-values'?: {}
name: string
slug: string
price: { value?: number; unit?: string }
'compare-at-price'?: { value?: number; unit?: string }
'ec-sku-billing-method'?: 'one-time' | 'subscription'
'ec-sku-subscription-plan'?: {
interval?: 'day' | 'week' | 'month' | 'year'
frequency?: number
trial?: number
plans?: {
platform?: 'stripe'
id?: string
status?: 'active' | 'inactive' | 'canceled'
}[]
}
'track-inventory'?: false | true
quantity?: number
}
}[]
}
) {
const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/products/${product_id}/skus`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 514 days ago