npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

samanage-api

v2.7.1

Published

Library for performing API calls to Samanage Helpdesk Service

Downloads

155

Readme

samanage-api

This is my personal API library for performing calls to The Samanage Service Platform. 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.

samanage-api code is reviewed with Codacy Badge and unit tested with

Try it

Installation

npm install samanage-api

Initialize

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, ref, pagination_info}) {...}
var failure = function({error, info, httpStatus, ref}) {...}
var request = ... // see below different requests
connection.callSamanageAPI(request).then(success).catch(failure)

Setting value for 'ref'

The 'ref' attribute in the success and failure callbacks can be set during the call itself, like so:

var my_ref = 'whatever custom information. can also be of any type'
connection.callSamanageAPI(request, my_ref).then(success).catch(failure)

Retries

Retries are supported out of the box for certain HTTP codes which are retryable

you can configure the retry logic

var OPTS = { // see 'retry' npm module for full documentation
  retries: 3,
  factor: 2,
  minTimeout: 1 * 100,
  maxTimeout: 60 * 100,
  randomize: true,
}

// For all requests on a specific connection
connection.retry_opts = OPTS
connection.callSamanageAPI(request, ref).then(...).catch(...)

// For a particular request
request.retry_opts = OPTS 
connection.callSamanageAPI(request, ref).then(...).catch(...)

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)

Export with filters

var export_incidents = SamanageAPI.export('incident')
connection.callSamanageAPI(
  export_incidents(
    new SamanageAPI.Filters().between_dates('created','2017-01-01','2018-07-07')
  )
).then(function (result) {
  /* Success:
    result contains pagination info (how many incidents are there) but
    does NOT contain the incidents' data. It is sent via email
  */
}).catch(function(error) {
  // Failure
})

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'
})

List of all functions and constants

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.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:

// promise to get all ITSM states:
var itsm_states = connection.getter('itsm_state')

// promise to get all users created between certain dates
var users_filter = (new SamanageAPI.Filter()).between_dates('created','2017-01-01','2018-07-07')
var users = connection.getter('user', users_filter)

// promise to get all comments of particular incident
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]) {...}
)