0

Disconnect Vendor Type

by
Published Nov 5, 2024

Disconnect a specific vendor type from the User's account. Assets of this type from that Vendor will be removed. If no other types from that vendor remain, all its stored data will be deleted.

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
	userId: string,
9
	vendor: string,
10
	vendorType: 'vehicle' | 'charger' | 'hvac' | 'inverter' | 'battery' | 'meter'
11
) {
12
	const url = new URL(
13
		`https://enode-api.production.enode.io/users/${userId}/vendors/${vendor}/${vendorType}`
14
	)
15

16
	const response = await fetch(url, {
17
		method: 'DELETE',
18
		headers: {
19
			Authorization: 'Bearer ' + auth.token
20
		},
21
		body: undefined
22
	})
23

24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28

29
	return await response.text()
30
}
31