0

Create a Tariff

by
Published Nov 5, 2024

Create a tariff using a list of names and prices. Before the tariff can be used in Enode products, it must be [linked to a location](https://developers.enode.com/api/reference#associateUserLocationWithTariff).

Script enode Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Enode = {
3
	token: string
4
}
5

6
export async function main(auth: Enode, tariffId: string, body: { name: string; cost: string }[]) {
7
	const url = new URL(`https://enode-api.production.enode.io/tariffs/${tariffId}`)
8

9
	const response = await fetch(url, {
10
		method: 'PUT',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Bearer ' + auth.token
14
		},
15
		body: JSON.stringify(body)
16
	})
17

18
	if (!response.ok) {
19
		const text = await response.text()
20
		throw new Error(`${response.status} ${text}`)
21
	}
22

23
	return await response.text()
24
}
25