We have provided an example code base written in JavaScript that can be executed on the command line with NodeJS.

Requirements

We recommend using Visual Studio Code as an IDE.

The ZIP file contains the following files:

Config.json

This is a configuration file. Update with your credentials / service account:

{
    "user": "admin",
    "pass": "admin",
    "baseurl": "https://cloud.lancom.de",
    "otpSecret: ""
}

If you are using two-factor authentication, you need to provide the secret via otpSecret, otherwise leave empty. If provided, the lmc-api.js will then generate tokens with this secret.

lmc-api.js, util.js

Library files.

lmc-api.js contains the authentication/authorization mechanism, including a token cache that reuses valid tokens and automatically refreshes tokens if needed.

util.js simplifies writing examples. See below.

get-sites.js

An example implementation to fetch a list of site UUIDs from a project:

const util = require("./util.js");

if (!util.checkParams(["account-uuid"])) { // add more cli parameters here
    return;
}

// Create an API object, to query the given account
const lmcApi = util.getApi(process.argv[2]);
// next cli parameter would be process.argv[3]

lmcApi.fetch(`/cloud-service-devices/accounts/${lmcApi.accountId}/sites?select=id`)
    .then(sites => {
        sites
            .forEach(site => console.log(site));
    });

Usage:

# node get-sites.js
Usage:
node get-sites.js <account-uuid>

Exercise:

Create a file get-devices.js, similar to get-projects.js and print a list of project IDs and names on the command line.