//native
type Webflow = {
token: string
}
export async function main(
auth: Webflow,
site_id: string,
product_id: string,
sku_id: string,
body: {
publishStatus?: 'staging' | 'live'
sku: {
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/${sku_id}`
)
const response = await fetch(url, {
method: 'PATCH',
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 564 days ago