Note: This article is intended for advanced technical users. If you have any questions, get in touch with us by sending a message to the chat or at support@logmore.com.
Prerequisites
- a Logmore account
- It also helps to have at least one Logmore data logger for testing.
Make your first API request
- Open Logmore Cloud UI to generate API key: https://web.logmore.com/settings/integrations
- Press
Generate a new API key
-button - Copy API key and secret and save them somewhere safe. You can't get the API secret from our Cloud UI after this as it's crypted to our database. API key and name will still be visible.
- Authorize yourself with API key and secret and you get a valid JWT in response:
curl -sS -X POST <https://api-c2.logmore.com/authenticate> \\
-d '{"key_id": "123123123123123123",
"api_key": "123123123123123123123123123123123123123123123123123123123123123123"}'
Once you have valid a JWT it must be placed into the header of subsequent requests.
Headers:
Authorization: Bearer <JWT>
Examples
Here are example scripts to get you started as quickly as possible.
Bash: Get a list of your loggers
Note: Requires curl and jq - apt install curl jq
#!/bin/sh
echo "Getting JWT...\\n"
JWT=$( \\
curl -sS -X POST <https://api-c2.logmore.com/authenticate> \\
-d '{"key_id": "123123123123123123",
"api_key": "123123123123123123123123123123123123123123123123123123123123123123"}' \\
| jq -r '.auth_token' \\
)
echo "Your JWT: $JWT\\n\\n"
echo "Getting loggers...\\n"
LOGGERS=$( \\
curl -sS -X POST <https://api-c2.logmore.com/loggers-search> \\
-d '{}' -H "Authorization: Bearer $JWT" \\
)
echo "Your loggers:"
echo $LOGGERS
Example output:
loggereer@QRM:~/logmore-examples$ ./get-tags.sh
Getting JWT...
Your JWT: 123123.123123123123123.123123
Getting loggers...
Your loggers:
[
{
"id": "5b05504d87d4ab0562f89d7d",
"created_at": "2018-01-01T12:34:18Z",
"updated_at": "2018-01-02T12:34:18Z",
"linked_at": "2018-01-03T12:34:18Z",
"owner_id": "ypklr41jpu",
"type": "Tag",
"name": "Logger1",
"config_id": "5c6406ee19fe0c26e14b0b0b",
"note": "This is a free text note",
"location_note": "This logger is at some place!",
"hardware": "",
"device_last_config": 8,
"serial": 10000,
"model": "Model 2",
"last_active": "2018-12-20T12:00:00Z",
"missions": [],
"single_use_tag": false,
"channels": [
{
"id": 0,
"name": "Temperature",
"unit": "'C",
"channel_conf": null
}
],
"latest_measurements": [
{
"channel_id": 0,
"name": "Temperature",
"unit": "'C",
"last_val": 23.6,
"last_date": "2018-12-20T12:00:00Z"
}
],
"comments": [
{
"created_at": "2018-01-01T12:34:18Z",
"updated_at": "2018-01-02T12:34:18Z",
"id": "5c014435d95a4e002c46e19d",
"user_id": "5bbf23720739b2001e6c5ada",
"user_name": "John Doe",
"user_email": "john@logmore.com",
"comment": "This is a the actual comment text",
"logger_id": "5b05504d87d4ab0562f89d7d"
}
],
"allowed_operations": [
"can_edit",
"can_read",
"logger_can_read_comments",
"logger_can_leave_comments",
"can_see_logger_location_history"
]
}
]
NodeJS
1. Authenticate
const axios = require('axios');
const url = 'https://api-c2.logmore.com/authenticate';
const data = {
key_id: "insert key_id here ...",
api_key: "insert api_key here ..."
};
axios.post(url, data, {
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
2. Use auth_token from previous request’s response as a Bearer token.
const axios = require('axios');
const auth_token = "insert token here ...";
const url = 'https://api-c2.logmore.com/loggers/5d3705874f05e9002dad9fd8';
const headers = {
'Authorization': `Bearer ${auth_token}`,
'Content-Type': 'application/x-www-form-urlencoded'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Check the full API reference at https://learn.logmore.com/ref/.