0

Get User Charging Statistics

by
Published Nov 5, 2024

Get statistics about power consumption and price in the form of a time series for a single device. If Smart Charging has shifted the consumption, the `nonSmartPrice` fields will show what the consumption would have cost if it had happened at the default time. If Smart Charging has resulted in savings, the value is reported in the `estimatedSavings` field.

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
	startDate: string | undefined,
10
	endDate: string | undefined,
11
	locationId: string | undefined,
12
	id: string | undefined,
13
	type: 'charger' | 'vehicle' | 'hvac' | undefined,
14
	utcOffset: string | undefined,
15
	resolution: 'QUARTER_HOUR' | 'HALF_HOUR' | 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'YEAR' | undefined
16
) {
17
	const url = new URL(`https://enode-api.production.enode.io/users/${userId}/statistics/charging`)
18

19
	for (const [k, v] of [
20
		['startDate', startDate],
21
		['endDate', endDate],
22
		['locationId', locationId],
23
		['id', id],
24
		['type', type],
25
		['utcOffset', utcOffset],
26
		['resolution', resolution]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32

33
	const response = await fetch(url, {
34
		method: 'GET',
35
		headers: {
36
			Authorization: 'Bearer ' + auth.token
37
		},
38
		body: undefined
39
	})
40

41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45

46
	return await response.json()
47
}
48