Edits history of script submission #9444 for ' Create Product & SKU (webflow)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Webflow = {
    	token: string
    }
    
    export async function main(
    	auth: Webflow,
    	site_id: string,
    	body: {
    		publishStatus?: 'staging' | 'live'
    		product?: {
    			fieldData?: {
    				name?: string
    				slug?: string
    				description?: string
    				shippable?: false | true
    				'sku-properties'?: {
    					id: string
    					name: string
    					enum: { id: string; name: string; slug: string }[]
    				}[]
    				categories?: string[]
    				'tax-category'?:
    					| 'standard-taxable'
    					| 'standard-exempt'
    					| 'books-religious'
    					| 'books-textbook'
    					| 'clothing'
    					| 'clothing-swimwear'
    					| 'digital-goods'
    					| 'digital-service'
    					| 'drugs-non-prescription'
    					| 'drugs-prescription'
    					| 'food-bottled-water'
    					| 'food-candy'
    					| 'food-groceries'
    					| 'food-prepared'
    					| 'food-soda'
    					| 'food-supplements'
    					| 'magazine-individual'
    					| 'magazine-subscription'
    					| 'service-admission'
    					| 'service-advertising'
    					| 'service-dry-cleaning'
    					| 'service-hairdressing'
    					| 'service-installation'
    					| 'service-miscellaneous'
    					| 'service-parking'
    					| 'service-printing'
    					| 'service-professional'
    					| 'service-repair'
    					| 'service-training'
    				'default-sku'?: string
    				'ec-product-type'?:
    					| 'ff42fee0113744f693a764e3431a9cc2'
    					| 'f22027db68002190aef89a4a2b7ac8a1'
    					| 'c599e43b1a1c34d5a323aedf75d3adf6'
    					| 'b6ccc1830db4b1babeb06a9ac5f6dd76'
    			} & {}
    		}
    		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`)
    
    	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 581 days ago