0

Creates a plan

by
Published Oct 17, 2025

Creates a new plan 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 plan
7
 * Creates a new plan for this bucket.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	bucketId: string,
12
	body: {
13
		label: string
14
		planExternalId: string
15
		meters: {}
16
		trialDays?: number
17
		trialEndStatus?: 'paused' | 'canceled'
18
		isTrialCollectPayment?: false | true
19
	}
20
) {
21
	const url = new URL(`https://dev.zuplo.com/v1/metering/${bucketId}/plans`)
22

23
	const response = await fetch(url, {
24
		method: 'POST',
25
		headers: {
26
			'Content-Type': 'application/json',
27
			Authorization: 'Bearer ' + auth.apiKey
28
		},
29
		body: JSON.stringify(body)
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.json()
36
}
37