https://github.com/eetay/samanage-api-js
A node.js module for performing API calls to Samanage Helpdesk Service.
https://github.com/eetay/samanage-api-js
api helpdesk helpdesk-professionals helpdesk-ticketing itam itsm node nodejs samanage samanage-api ticket-management ticketing-system
Last synced: 6 months ago
JSON representation
A node.js module for performing API calls to Samanage Helpdesk Service.
- Host: GitHub
- URL: https://github.com/eetay/samanage-api-js
- Owner: eetay
- Created: 2018-05-24T09:53:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-21T05:26:30.000Z (about 7 years ago)
- Last Synced: 2025-03-28T12:21:13.471Z (6 months ago)
- Topics: api, helpdesk, helpdesk-professionals, helpdesk-ticketing, itam, itsm, node, nodejs, samanage, samanage-api, ticket-management, ticketing-system
- Language: JavaScript
- Homepage:
- Size: 270 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# samanage-api
This is my personal API library for performing calls to [The Samanage Service Platform](https://www.samanage.com/service-desk/). 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 [](https://www.codacy.com/app/eetay/samanage-api-js?utm_source=github.com&utm_medium=referral&utm_content=eetay/samanage-api-js&utm_campaign=Badge_Grade)
and unit tested with JestIf you'd like to contribute, you are welcome to fork, and submit pull requests to the original library, or contact me at eetay.natan@samanage.com
[Try it on runKit](https://npm.runkit.com/samanage-api) (You will need a Samanage API token. [How to get a token](https://community.samanage.com/docs/DOC-1459-encrypted-tokens-authentication-for-api-integration-overview))
## Installation
```bash
npm install samanage-api
```## Initialize
You will need a Samanage API token. [How to get a token](https://community.samanage.com/docs/DOC-1459-encrypted-tokens-authentication-for-api-integration-overview)```javascript
var SamanageAPI = require('samanage-api')
var connection = new SamanageAPI.Connection("your-token-here")
```## Making a call
```javascript
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:```javascript
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 retryableyou can configure the retry logic
```javascript
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
```javascript
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
```javascript
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
```javascript
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
```javascript
var request = SamanageAPI.update('incident')(3, {
name:'opened with samanage-api-js library'
})
```## Create
```javascript
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:```javascript
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 experimentGetters are defined like this:
```javascript
// 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
```javascript
Promise.all([itsm_states, users]).then(
function([states, users]) {...}
)
```