⌨

Logmore API

Note: This article is intended for advanced technical users.

Logmore offers free to use open REST API.

Full API reference can be found at: πŸ”— https://learn.logmore.com/ref/

❓

Need help? Have questions? Get in touch with your Logmore contact or send us a message at support@logmore.com.

Getting started

Prequisities: You should have a Logmore account. It also helps to have at least one

for testing.

Follow these steps to make your first api request:

  • Open Logmore Cloud UI to generate API key:Β https://web.logmore.com/usersettings
  • 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 list of your tags

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

var request = require("request");
​
var options = { method: 'POST',
  url: 'https://api-c2.logmore.com/authenticate',
  headers: 
   { 'Content-Type': 'application/json' },
  body: 
   { key_id: '{key_id}',
     api_key: '{api_key}' },
  json: true };
​
request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
  // prints something like {"auth_token": "aabcb1234343434"}
}
});

2 - Use auth_token from previous request’s response as a Bearer token.

var request = require("request");
​
var options = { method: 'GET',
  url: 'https://api-c2.logmore.com/loggers/5d3705874f05e9002dad9fd8',
  headers:
   {
     Authorization: 'Bearer {auth_token from response'}
     'Content-Type': 'application/x-www-form-urlencoded' },
  form: false };
​
request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});

Check the full API reference at πŸ”— https://learn.logmore.com/ref/

Continue reading: