Edits history of script submission #22215 for ' Updates a subscription (zuplo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zuplo = {
    	apiKey: string
    }
    /**
     * Updates a subscription
     * Updates the subscription for this bucket.
     */
    export async function main(
    	auth: Zuplo,
    	bucketId: string,
    	subscriptionId: string,
    	body: {
    		planExternalIds?: string[]
    		status?:
    			| 'active'
    			| 'inactive'
    			| 'incomplete'
    			| 'incomplete-expired'
    			| 'trialing'
    			| 'past-due'
    			| 'canceled'
    			| 'unpaid'
    			| 'paused'
    		prorate?: number
    		metadata?: {}
    		trialEndDate?: string
    	}
    ) {
    	const url = new URL(
    		`https://dev.zuplo.com/v1/metering/${bucketId}/subscriptions/${subscriptionId}`
    	)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		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 235 days ago