Skip to content
Javascript Client
JavaScript Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.swagger-codegen
docs
src
test
.gitignore
.npmignore
.swagger-codegen-ignore
.travis.yml
LICENSE
README.md
git_push.sh
mocha.opts
package-lock.json
package.json
webpack.config.js

README.md

WAZIUP-JS

Waziup-js is a javascript client to interact with the Waziup plaform.

Installation

Install it via:

npm install --save -g waziup-js

Getting Started

Here is an example code to retrieve all devices from Waziup:

const WaziupApi = require("waziup-js");

WaziupApi.ApiClient.instance.basePath = "https://api.waziup.io/api/v2";
var api = new WaziupApi.DevicesApi();

api.getDevices().then(devices => {
  console.log("List of devices: ", JSON.stringify(devices));
});

Save this file as test.js and run:

node test.js

You should get a list of devices. The format of the devices is given here.

Authentication

You need a token to access protected resources. You can retrieve one like that:

const WaziupApi = require("waziup-js");

WaziupApi.ApiClient.instance.basePath = "https://api.waziup.io/api/v2";
var deviceApi = new WaziupApi.DevicesApi();
var authApi = new WaziupApi.AuthApi();

//Deleting a resource requires authentication
async function testDelete() {
  var token = await authApi.getAuthToken(
    "waziup",
    new WaziupApi.AuthBody("YOUR_USERNAME", "YOUR_PASSWORD")
  );
  WaziupApi.ApiClient.instance.authentications["Bearer"].apiKey =
    "Bearer " + token;

  try {
    await deviceApi.deleteDevice("MyDevice");
  } catch (error) {
    console.log("Error " + error.status);
  }
}

testDelete();

You should create a user beforehand on https://dashboard.waziup.io. As a rule of thumb, you can only update or delete resources that you are owner of.

Documentation for API Endpoints

There are 8 endpoints:

Documentation for Models

Documentation for Authorization

Bearer

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Developement

Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your waziup-js from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('waziup-js') in javascript files from the directory you ran the last command above from.

Publish

Simply type:

npm publish
You can’t perform that action at this time.