0

Update Vehicle Smart Charging Policy

by
Published Nov 5, 2024

Updates the Smart Charging policy for a vehicle

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(
7
	auth: Enode,
8
	vehicleId: string,
9
	body: {
10
		isEnabled?: false | true
11
		deadline?: string
12
		minimumChargeLimit?: number
13
	}
14
) {
15
	const url = new URL(
16
		`https://enode-api.production.enode.io/vehicles/${vehicleId}/smart-charging-policy`
17
	)
18

19
	const response = await fetch(url, {
20
		method: 'PUT',
21
		headers: {
22
			'Content-Type': 'application/json',
23
			Authorization: 'Bearer ' + auth.token
24
		},
25
		body: JSON.stringify(body)
26
	})
27

28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32

33
	return await response.json()
34
}
35