0
Update Plan
One script reply has been approved by the moderators Verified
Created by hugo697 127 days ago Viewed 991 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 127 days ago
1
type Baremetrics = {
2
	apiKey: string
3
}
4

5
export async function main(
6
	resource: Baremetrics,
7
	sourceId: string,
8
	oid: string,
9
	body: {
10
		name: string
11
	}
12
) {
13
	const endpoint = `https://api.baremetrics.com/v1/${sourceId}/plans/${oid}`
14

15
	const response = await fetch(endpoint, {
16
		method: 'PUT',
17
		headers: {
18
			'Content-Type': 'application/json',
19
			Accept: 'application/json',
20
			Authorization: `Bearer ${resource.apiKey}`
21
		},
22
		body: JSON.stringify(body)
23
	})
24

25
	if (!response.ok) {
26
		throw new Error(`HTTP error! status: ${response.status}`)
27
	}
28

29
	const data = await response.json()
30

31
	return data.plan
32
}
33