@vdocdk/meterportal-internal-client
v1.1.20
Published
Internal api client wrapper for meterportal.eu
Downloads
29
Readme
Installation
npm i @vdocdk/meterportal-internal-client
- follow usage
Usage:
import MeterportalInternal from '@vdocdk/meterportal-internal-client';
const { api, login } = new MeterportalInternal();
const example = async () => {
//Login if auth needed.
await login({ username: '[email protected]', password: 'xxxxxx' });
const testRequest = await api.getAddressMetrics('utilityId', 'addressId');
console.log(testRequest);
};
example();
Persist token
import MeterportalInternal from '@vdocdk/meterportal-internal-client';
const { api, login, config } = new MeterportalInternal();
//load from localStorage
config.setToken(window.localStorage.getItem('token'));
config.setRefreshToken(window.localStorage.getItem('refresh-token'));
//event to update then tokens updated in config, then save in localstorage
config.on('setToken', (new_token) => window.localStorage.setItem('token', new_token));
config.on('refreshToken', (new_refresh_token) => window.localStorage.setItem('refresh-token',new_refresh_token));
//example
const example = async () => {
//Login if auth needed.
const user = await login({ username: '[email protected]', password: 'xxxxxx' });
if(!user) throw new Error('Wrong login');
const testRequest = await api.getAddressMetrics('utilityId', 'addressId');
console.log(testRequest);
};
example();
Author
vdoc ApS Support and help at vdoc.dk