5.12.1 • Published 5 years ago

node-meraki v5.12.1

Weekly downloads
12
License
MIT
Repository
github
Last release
5 years ago

node-meraki

Nodejs wrapper module for Cisco Meraki network manager. Currentyl we support the Meraki API version v0.

Build Status

Installation

npm install --save node-meraki

Documentation

The jsdoc documentation can be found here

Options

NameTypeDescriptionDefault
versionStringWhich Meraki api version to usev0
apiKeyStringThe Meraki api key
targetStringThe Meraki targetapi
baseUrlStringThe Meraki base urlhttps://api.meraki.com
frontendbooleanActivates the frontend API toofalse
emailstringE-Mail for the Frontend (mandatory if frontend is set to true)
passwordstringPassword for the Frontend (mandatory if frontend is set to true)
rateLimiterObjectThe rate limiter bottleneck configurationsee Rate-Limiter section
loggerEnabledbooleanIf enabled node-meraki will log request informationfalse
loggerobjectCustom loggerconsole

ApiKey and Target

It is recommended to set the apiKey on the initial module configuration. This key will be used for all subsequent api requests. If you need to set the apiKey on a request-level you have the possebility to pass it along for each request.

You have the following three possebilities to set the target:

  1. On the initial configuration level. This target will be used for all subsequent api requests.
  2. Leave the target blank. In this case the module will use the api target which triggers a redirect upon requests. The redirects are handled by this module.
  3. Set the target for each request.

Rate-Limiter

We make use of the bottleneck module to implement rate limited requests against the Meraki API. Most users will have a 5-requests-per-second rate limit. To enabled this functionality, pass the following configuration as options:

const rateLimiter = {
  enabled: true
};

Scoped Rate-Limiter

If you manage more than one organisation you can enable the Rate-Limiter to use a pool of instances, one instance for each organisation (Meraki rate limit is restricted on a per-organisation level). Simply pass the scoped=true settings on node-meraki initialization. Each request accepts a scope attribute (for example the organisation id) which will be used to access the scoped Rate-Limiter instance. If no instance exists for the given instance one will be created on the fly and stored in the pool for all following requests.

Following configuration defaults are set and can be overwritten:

const rateLimiter = {
  enabled: false,
  maxConcurrent: 5,
  minTime: 200,
  highWater: 1000,
  strategy: Bottleneck.strategy.LEAK,
  scoped: false
};

Usage

const apiKey = "secret meraki api key";
const organizationId = "meraki organization id";
const version = "v0";
const target = "n12";
const rateLimiter = {
  enbaled: true
};
const baseUrl = "https://api.meraki.com"; // this is the default an can be overwritten

// baseUrl and port are optional
const meraki = require("./lib")({
  version,
  apiKey,
  target,
  baseUrl,
  rateLimiter
});

function handleErrors(error) {
  if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    console.log(error.response.data);
    console.log(error.response.status);
    console.log(error.response.headers);
  } else if (error.request) {
    // The request was made but no response was received
    // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
    // http.ClientRequest in node.js
    console.log(error.request);
  } else {
    // Something happened in setting up the request that triggered an Error
    console.log("Error", error.message);
  }
  console.log(error.config);
}

function handleSuccess(data) {
  console.log(data);
}

meraki
  .listOrganizations()
  .then(handleSuccess)
  .catch(handleErrors);

Raw Requests

If you'd like to use an endpoint which is not included in this project you can make us of the raw requests. Init the meraki lib as described above and use one of the following methods:

// get
meraki.getRaw({
  target: "your target (optional, see above)",
  scope: "your scope (optional, see above)",
  path: "api/<version>/<sub>/<path>"
});

// post
meraki.postRaw({
  target: "your target (optional, see above)",
  scope: "your scope (optional, see above)",
  path: "api/<version>/<sub>/<path>",
  data: {}
});

// put
meraki.putRaw({
  target: "your target (optional, see above)",
  scope: "your scope (optional, see above)",
  path: "api/<version>/<sub>/<path>",
  data: {}
});

// delete
meraki.deleteRaw({
  target: "your target (optional, see above)",
  scope: "your scope (optional, see above)",
  path: "api/<version>/<sub>/<path>"
});

Debugging

Set DEBUG=node-meraki* to see internal logs

Contribute

It would be great to enhance the node-meraki API wrapper to include all missing endpoints (see Currently not implemented). If you want to contribute to this repository please provide a pull-request and make sure to:

  • conform to the current directory style guide
  • conform to the current jsdoc documentation

Currently not implemented

All endpoints for ressources for:

  • Air Marshal scans
  • Bluetooth
  • Firewfall
  • SM
  • VPN
5.12.1

5 years ago

5.12.0

5 years ago

5.11.0

5 years ago

5.10.1

5 years ago

5.10.0

5 years ago

5.9.3

5 years ago

5.9.2

5 years ago

5.9.1

5 years ago

5.9.0

5 years ago

5.8.0

5 years ago

5.7.0

5 years ago

5.6.0

5 years ago

5.5.0

5 years ago

5.4.0

5 years ago

5.3.0

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.0.1

5 years ago

4.0.0

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.0

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago