Seiteneigenschaften |
---|
We have provided an example code base written in JavaScript that can be executed on the command line with NodeJS.
Requirements
- download the latest stable version from https://nodejs.org/en/.
- download the minimal-lmc-api-setup.zip, and unpack it in your workspace.
- run
npm install
to download dependencies required by the example code
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:
Codeblock |
---|
{
"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:
Codeblock |
---|
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:
Codeblock |
---|
# node get-sites.js
Usage:
node get-sites.js <account-uuid> |
Info |
---|
Exercise: Create a file |