0

Creates a subscription

by
Published Oct 17, 2025

Creates a new 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
 * Creates a subscription
7
 * Creates a new subscription for this bucket.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	bucketId: string,
12
	body: {
13
		planIds: string[]
14
		planExternalIds: string[]
15
		quotaResetAnchor?: string
16
		status:
17
			| 'active'
18
			| 'inactive'
19
			| 'incomplete'
20
			| 'incomplete-expired'
21
			| 'trialing'
22
			| 'past-due'
23
			| 'canceled'
24
			| 'unpaid'
25
			| 'paused'
26
		type: 'periodic'
27
		renewalStrategy: 'monthly' | 'yearly'
28
		region: 'us-central1' | 'us-east1' | 'europe-west4'
29
		customerKey: string
30
		subscriptionExternalId: string
31
		customerExternalId: string
32
		metadata?: {}
33
		trialEndStatus?: string
34
		trialEndDate?: string
35
		trialStartDate?: string
36
	}
37
) {
38
	const url = new URL(`https://dev.zuplo.com/v1/metering/${bucketId}/subscriptions`)
39

40
	const response = await fetch(url, {
41
		method: 'POST',
42
		headers: {
43
			'Content-Type': 'application/json',
44
			Authorization: 'Bearer ' + auth.apiKey
45
		},
46
		body: JSON.stringify(body)
47
	})
48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52
	return await response.json()
53
}
54