0

Link User

by
Published Nov 5, 2024

Creates a short-lived (24 hours), single-use device linking session. Use the returned `linkUrl` to present Link UI to your user via mobile in-app browsers or web redirects, or use the `linkToken` to present Link UI via the Link SDKs.

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
	body: {
10
		vendor?:
11
			| 'APSYSTEMS'
12
			| 'CSISolar'
13
			| 'Deye'
14
			| 'ENPHASE'
15
			| 'FOXESS'
16
			| 'FRONIUS'
17
			| 'GOODWE'
18
			| 'GROWATT'
19
			| 'Hoymiles'
20
			| 'HUAWEI'
21
			| 'INVT'
22
			| 'SMA'
23
			| 'SOFAR'
24
			| 'SOLAREDGE'
25
			| 'SOLARK'
26
			| 'SOLAX'
27
			| 'SOLIS'
28
			| 'SOLPLANET'
29
			| 'SUNGROW'
30
			| 'SUNSYNK'
31
			| 'TESLA'
32
			| 'TSUN'
33
			| 'AUDI'
34
			| 'BMW'
35
			| 'HONDA'
36
			| 'HYUNDAI'
37
			| 'JAGUAR'
38
			| 'LANDROVER'
39
			| 'KIA'
40
			| 'MERCEDES'
41
			| 'MINI'
42
			| 'NISSAN'
43
			| 'PEUGEOT'
44
			| 'PORSCHE'
45
			| 'RENAULT'
46
			| 'SEAT'
47
			| 'SKODA'
48
			| 'VOLKSWAGEN'
49
			| 'VOLVO'
50
			| 'FORD'
51
			| 'OPEL'
52
			| 'DS'
53
			| 'TOYOTA'
54
			| 'LEXUS'
55
			| 'CITROEN'
56
			| 'CUPRA'
57
			| 'VAUXHALL'
58
			| 'FIAT'
59
			| 'RIVIAN'
60
			| 'NIO'
61
			| 'CHEVROLET'
62
			| 'GMC'
63
			| 'CADILLAC'
64
			| 'XPENG'
65
			| 'TADO'
66
			| 'MILL'
67
			| 'ADAX'
68
			| 'ECOBEE'
69
			| 'SENSIBO'
70
			| 'HONEYWELL'
71
			| 'RESIDEO'
72
			| 'MITSUBISHI'
73
			| 'MICROMATIC'
74
			| 'NIBE'
75
			| 'PANASONIC'
76
			| 'TOSHIBA'
77
			| 'DAIKIN'
78
			| 'NEST'
79
			| 'FUJITSU'
80
			| 'BOSCH'
81
			| 'NETATMO'
82
			| 'ZAPTEC'
83
			| 'EASEE'
84
			| 'WALLBOX'
85
			| 'EO'
86
			| 'CHARGEAMPS'
87
			| 'EVBOX'
88
			| 'GOE'
89
			| 'CHARGEPOINT'
90
			| 'ENELX'
91
			| 'OHME'
92
			| 'GARO'
93
			| 'SCHNEIDER'
94
			| 'PODPOINT'
95
		vendorType:
96
			| ('vehicle' & {})
97
			| ('charger' & {})
98
			| ('hvac' & {})
99
			| ('inverter' & {})
100
			| ('battery' & {})
101
			| ('meter' & {})
102
		language:
103
			| 'browser'
104
			| 'da-DK'
105
			| 'de-DE'
106
			| 'en-US'
107
			| 'en-GB'
108
			| 'es-ES'
109
			| 'fi-FI'
110
			| 'fr-FR'
111
			| 'it-IT'
112
			| 'nb-NO'
113
			| 'nl-NL'
114
			| 'nl-BE'
115
			| 'pt-PT'
116
			| 'ro-RO'
117
			| 'sv-SE'
118
		scopes:
119
			| 'battery:control:operation_mode'
120
			| 'battery:read:data'
121
			| 'battery:read:location'
122
			| 'charger:control:charging'
123
			| 'charger:read:data'
124
			| 'hvac:control:mode'
125
			| 'hvac:read:data'
126
			| 'inverter:read:data'
127
			| 'inverter:read:location'
128
			| 'meter:read:data'
129
			| 'meter:read:location'
130
			| 'vehicle:control:charging'
131
			| 'vehicle:read:data'
132
			| 'vehicle:read:location'[]
133
		redirectUri: string
134
		colorScheme?: 'system' | 'light' | 'dark'
135
	}
136
) {
137
	const url = new URL(`https://enode-api.production.enode.io/users/${userId}/link`)
138

139
	const response = await fetch(url, {
140
		method: 'POST',
141
		headers: {
142
			'Content-Type': 'application/json',
143
			Authorization: 'Bearer ' + auth.token
144
		},
145
		body: JSON.stringify(body)
146
	})
147

148
	if (!response.ok) {
149
		const text = await response.text()
150
		throw new Error(`${response.status} ${text}`)
151
	}
152

153
	return await response.json()
154
}
155