Waziup-js is a javascript client to interact with the Waziup plaform.
Install it via:
npm install --save -g waziup-js
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.
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.
There are 8 endpoints:
- Auth API
- Sensors API
- Actuators API
- Devices API
- Gateways API
- Notifications API
- Projects API
- Socials API
- Users API
- WaziupApi.Actuator
- WaziupApi.AuthBody
- WaziupApi.Calib
- WaziupApi.CalibFunction
- WaziupApi.CalibLinear
- WaziupApi.CalibValue
- WaziupApi.Device
- WaziupApi.Error
- WaziupApi.Gateway
- WaziupApi.GatewayTunnel
- WaziupApi.Location
- WaziupApi.Notification
- WaziupApi.NotificationCondition
- WaziupApi.Sensor
- WaziupApi.Sensor
- WaziupApi.SensorValue
- WaziupApi.SocialMessage
- WaziupApi.SocialMessageBatch
- WaziupApi.User
- WaziupApi.UserUpdateBody
- Type: API key
- API key parameter name: Authorization
- Location: HTTP header
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.
Simply type:
npm publish