Package Exports
- samanage-api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (samanage-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
samanage-api
This is my personal helper code for performing API calls to Samanage Helpdesk Service. The code is provided as-is, without any warrenty. It is a work in progress and may not support all the options offered by the Samanage API Feel free to contact me with requests, issues or questions.
Installation
npm install samanage-apiInitialize
You will need a Samanage API token. How to get a token
var SamanageAPI = require('samanage-api')
var connection = new SamanageAPI.Connection("your-token-here")Making a call
var success = function(data) {...}
var failure = function(error) {...}
var request = ...
connection.callSamanageAPI(request).then(success).catch(failure)Retrieval with filters
var get_incidents = SamanageAPI.get('incident')
var request = get_incidents(
new SamanageAPI.Filters().add({
sort_order: 'ASC',
sort_by: 'created_at',
created: ['2018-01-01','2018-01-02']
})
)
connection.callSamanageAPI(...)Building filters
var get_incidents = SamanageAPI.get('incident')
var filters = new SamanageAPI.Filters().
sort_by('name').
sort_order(SamanageAPI.Filter.DESC).
between_dates('created','2018-01-01','2018-01-02').
per_page(100).
page(3)
var request = get_incidents(filters)Update
var request = SamanageAPI.update('incident')(3, {
name:'opened with samanage-api-js library'
})Create
var request = SamanageAPI.create('incident')({
name:'opened with samanage-api-js library'
})Help
SamanageAPI has built in help. Open a new node console, and execute this:
var SamanageAPI = require('samanage-api')
console.log(SamanageAPI.help)
console.log(SamanageAPI.Filters.help)
console.log(SamanageAPI.ItsmStates.help)
console.log(SamanageAPI.Connection.help)Getter objects
Getter objects are promises to get all items of certain type that match a specific SamanageAPI.Filter.
Getters are very convenient way of retrieving things like Itsm States or Users,
but may not be proper strategy for retrieving very large sets of items
(e.g. all audit logs since start of time);
Currently there's no check on number of items which will cause a very long retrieval process so just go ahead and experiment
Getters are defined like this:
var users_filter = new SamanageAPI.Filter()
var users = connection.getter('user', users_filter)
var itsm_states = connection.getter('itsm_state')
var comments = connection.getter('comment', (new SamanageAPI.Filters()), 'incidents/' + incident.id)Example: Do something after both users and itsm states are retrieved
Promise.all([itsm_states, users]).then(
function([states, users]) {...}
)