monster.request()

Syntax

monster.request(options);

Parameters

options is a mandatory Object parameter with the following properties:

KeyDescriptionTypeDefaultRequire
resourceUnique identifier corresponding to a request.Objecttrue
dataParameters to pass to the request.Objectfalse
successCallback on success.Functionfalse
errorCallback on error.Functionfalse

Description

The monster.request() method allows you to make requests that are not defined in the Kazoo JavaScript SDK.

To specify the options of the request, add an entry in the requests object at the root level of the application. The key needs to be a unique identifier that will be used to call the API. By default, the apiRoot is monster.config.api.default.

Examples

Delete a device on the provisioner

var monster = require('monster');

var app = {
  // Define API requests not included in the SDK
  requests: {
    'provisioner.devices.delete': {
      apiRoot: monster.config.api.provisioner,
      url: 'devices/{accountId}/{macAddress}',
      verb: 'DELETE'
    }
  }
};

function requestDeleteDevice(args) {
  monster.request({
    resource: 'provisioner.devices.delete',
    data: {
      accountId: args.accountId,
      macAddress: args.maccAddress
    },
    success: function() {
      args.hasOwnProperty('success') && args.success();
    },
    error: function() {
      args.hasOwnProperty('error') && args.error();
    }
  });
}

// Do something with `requestDeleteDevice`

Use Google Maps Geocoding API to get information about a ZIP code:

var app = {
  //Defines API requests not included in the SDK
  requests: {
    'google.geocode.zipCode': {
      apiRoot: 'https://maps.googleapis.com/',
      url: 'maps/api/geocode/json?components=country:{country}|postal_code:{zipCode}',
      verb: 'GET',
      generateError: false,
      removeHeaders: [
        'X-Kazoo-Cluster-ID',
        'X-Auth-Token',
        'Content-Type'
      ]
    }
  }
};

function requestGetAddressFromZipCode(args) {
  monster.request({
    resource: 'google.geocode.zipCode',
    data: {
      country: args.country,
      zipCode: args.zipCode
    },
    success: function(data, status) {
      args.hasOwnProperty('success') && args.success(data.results);
    },
    error: function(data, status) {
      args.hasOwnProperty('error') && args.error();
    }
  });
}

// Do something with `requestGetAddressFromZipCode`

In this example, we had to remove a set of headers using the removeHeaders key so the server would accept the request and also had to disable the automatic Monster Error Popup with generateError.

On this page