First you'll need a CLIENT_ID
and CLIENT_SECRET
provided by LEKTRI.CO team. Once you have those keys, you can start using the API. In order to connect follow these steps:
You need to make a POST request to our auth URL https://api.lektri.co/oauth/token
to get an access token. You have to provide the credentials CLIENT_ID
and CLIENT_SECRET
.
If you are using cURL:
curl -i -X POST \
-d "{\"grant_type\":\"client_credentials\",\"scope\":\"*\",\"client_id\": CLIENT_ID,\"client_secret\": CLIENT_SECRET}" \
-H "Content-Type: application/json" \
https://api.lektri.co/oauth/token
If you are using javascript:
axios.post('https://api.lektri.co/oauth/token', {
'grant_type': 'client_credentials',
'scope': '*',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET
})
After the token call, you receive a response containing the access_token
attribute which holds the token:
If you are using cURL:
{"token_type":"Bearer","expires_in":31536000,"access_token":"eyJ0eX..."}
If you are using javascript:
axios.post('https://api.lektri.co/oauth/token', {
'grant_type': 'client_credentials',
'scope': '*',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET
}).then(({ data }) => {
const { access_token } = data;
// Inspect the token
logger.log('Token acquired successfully: ', access_token);
})
You can now use the access_token
for further calls passing it to the Authorization
header for each call. The header must follow this format: Authorization: Bearer {access_token}
where {access_token}
is replaced with your token.
NOTE: Please bear in mind that this
access_token
hasclient_credentials
and notpassword_credentials
which means it's not associated with any of the users. That being said, the endpoints/user
and/user/items
will respond with unauthenticated message:{"message":"Unauthenticated."}
If you are using cURL:
curl -i \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer {access_token}" \
https://api.lektri.co/api/v1/stations/list
If you are using javascript:
// ...
const { access_token } = data;
const API_BASE_URL = 'https://api.lektri.co/api/v1/';
authAxios = axios.create({
baseURL: API_BASE_URL,
headers: {
common: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${access_token}`
}
}
});
For further assistance please contact LEKTRI.CO support here.