1.5.1 • Published 8 years ago

servicenow-api v1.5.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

ServiceNow API

This is a module that sends http requests to ServiceNow and returns an object with an array of incidents.

Installation

Install the module via npm specifying a version.

npm install servicenow-api --save

Configuration

The object is a function that is expecting config parameters to be passed.

// Modules
// The object passed can be omitted if the properties are set in the configs.

var servicenow = require('servicenow-api')({
	baseurl: 'https://mycompany.service-now.com/api/now/v1',
	auth: {
		user: 'myusername',
		pass: 'mypassword'
	},
	defaults: {
		proxy: 'http://proxy.mycompany.com:8080',
		agent: false
	},
	tableAPI: {
		incidents: 'incident', // label: 'endpoint'
		users: 'sys_user'
	}
});

Usage

After configuration the module will return an object with api endpoints.

var incidents = require('servicenow-api').tableAPI.incidents;

or

var servicenow = require('servicenow-api');
var incidents  = servicenow.tableAPI.incidents;
var users      = servicenow.tableAPI.users;

Methods

.create({object})

return incidents.create({ short_description: 'Create Me!'}).then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

.find({object})

return incidents.find({number:'=INC0034551'}).then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

.find(array)

return incidents.find(['number=INC0034551']).then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

.find('string')

return incidents.find('?sysparm_limit=3&sys_created_on>=javascript:gs.beginningOfThisYear()').then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

.find(sys_id)

return incidents.find('ed9378804f94a6405df4d0af0310c7b8').then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

.update(sys_id, {object})

return incidents.update('ed9378804f94a6405df4d0af0310c7b8', { short_description: 'Fix Me Now!'}).then(function (data)
{
	return data;
}).catch(function (err)
{
	throw err;
});

HTTP Authentication

https://github.com/request/request#http-authentication

request.get('http://some.server.com/').auth('username', 'password', false);
// or
request.get('http://some.server.com/', {
  'auth': {
    'user': 'username',
    'pass': 'password',
    'sendImmediately': false
  }
});
// or
request.get('http://some.server.com/').auth(null, null, true, 'bearerToken');
// or
request.get('http://some.server.com/', {
  'auth': {
    'bearer': 'bearerToken'
  }
});

If passed as an option, auth should be a hash containing values:

  • user || username
  • pass || password
  • sendImmediately (optional)
  • bearer (optional)

The method form takes parameters auth(username, password, sendImmediately, bearer).

sendImmediately defaults to true, which causes a basic or bearer authentication header to be sent. If sendImmediately is false, then request will retry with a proper authentication header after receiving a 401 response from the server (which must contain a WWW-Authenticate header indicating the required authentication method).

Note that you can also specify basic authentication using the URL itself, as detailed in RFC 1738. Simply pass the user:password before the host with an @ sign:

var username = 'username',
    password = 'password',
    url = 'http://' + username + ':' + password + '@some.server.com';

request({url: url}, function (error, response, body) {
   // Do more stuff with 'body' here
});

Digest authentication is supported, but it only works with sendImmediately set to false; otherwise request will send basic authentication on the initial request, which will probably cause the request to fail.

Bearer authentication is supported, and is activated when the bearer value is available. The value may be either a String or a Function returning a String. Using a function to supply the bearer token is particularly useful if used in conjunction with defaults to allow a single function to supply the last known token at the time of sending a request, or to compute one on the fly.


1.5.1

8 years ago

1.5.0

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago