0

Updates a subscription

by
Published Oct 17, 2025

Updates the subscription for this bucket.

Script zuplo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zuplo = {
3
	apiKey: string
4
}
5
/**
6
 * Updates a subscription
7
 * Updates the subscription for this bucket.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	bucketId: string,
12
	subscriptionId: string,
13
	body: {
14
		planExternalIds?: string[]
15
		status?:
16
			| 'active'
17
			| 'inactive'
18
			| 'incomplete'
19
			| 'incomplete-expired'
20
			| 'trialing'
21
			| 'past-due'
22
			| 'canceled'
23
			| 'unpaid'
24
			| 'paused'
25
		prorate?: number
26
		metadata?: {}
27
		trialEndDate?: string
28
	}
29
) {
30
	const url = new URL(
31
		`https://dev.zuplo.com/v1/metering/${bucketId}/subscriptions/${subscriptionId}`
32
	)
33

34
	const response = await fetch(url, {
35
		method: 'PATCH',
36
		headers: {
37
			'Content-Type': 'application/json',
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: JSON.stringify(body)
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48