{"id":26186657,"url":"https://github.com/eetay/samanage-api-js","last_synced_at":"2025-04-15T00:26:23.849Z","repository":{"id":65492520,"uuid":"134695791","full_name":"eetay/samanage-api-js","owner":"eetay","description":"A node.js module for performing API calls to Samanage Helpdesk Service.","archived":false,"fork":false,"pushed_at":"2018-08-21T05:26:30.000Z","size":276,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T12:21:13.471Z","etag":null,"topics":["api","helpdesk","helpdesk-professionals","helpdesk-ticketing","itam","itsm","node","nodejs","samanage","samanage-api","ticket-management","ticketing-system"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eetay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-24T09:53:22.000Z","updated_at":"2018-09-12T05:31:59.000Z","dependencies_parsed_at":"2023-01-26T01:45:55.309Z","dependency_job_id":null,"html_url":"https://github.com/eetay/samanage-api-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fsamanage-api-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fsamanage-api-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fsamanage-api-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eetay%2Fsamanage-api-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eetay","download_url":"https://codeload.github.com/eetay/samanage-api-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813803,"owners_count":21165634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","helpdesk","helpdesk-professionals","helpdesk-ticketing","itam","itsm","node","nodejs","samanage","samanage-api","ticket-management","ticketing-system"],"created_at":"2025-03-11T23:22:52.692Z","updated_at":"2025-04-15T00:26:23.819Z","avatar_url":"https://github.com/eetay.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# samanage-api\n\nThis 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.\nIt is a work in progress and may not support all the options offered by the Samanage API\nFeel free to contact me with requests, issues or questions.\n\nsamanage-api code is reviewed with [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b37abcd47e7a4753811ab872e644211a)](https://www.codacy.com/app/eetay/samanage-api-js?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=eetay/samanage-api-js\u0026amp;utm_campaign=Badge_Grade)\nand unit tested with Jest \u003cimg src=\"./spec/jest.png\" alt=\"Jest\" width=\"32px\"/\u003e\n\nIf 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\n\n[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))\n\n## Installation\n```bash\nnpm install samanage-api\n```\n\n## Initialize\nYou 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)\n\n```javascript\nvar SamanageAPI = require('samanage-api')\nvar connection = new SamanageAPI.Connection(\"your-token-here\")\n```\n\n## Making a call\n```javascript\nvar success = function({data, ref, pagination_info}) {...}\nvar failure = function({error, info, httpStatus, ref}) {...}\nvar request = ... // see below different requests\nconnection.callSamanageAPI(request).then(success).catch(failure)\n```\n\n### Setting value for 'ref'\nThe 'ref' attribute in the success and failure callbacks can be set during the\ncall itself, like so:\n\n```javascript\nvar my_ref = 'whatever custom information. can also be of any type'\nconnection.callSamanageAPI(request, my_ref).then(success).catch(failure)\n```\n\n### Retries\nRetries are supported out of the box for certain HTTP codes which are retryable\n\nyou can configure the retry logic\n\n```javascript\nvar OPTS = { // see 'retry' npm module for full documentation\n  retries: 3,\n  factor: 2,\n  minTimeout: 1 * 100,\n  maxTimeout: 60 * 100,\n  randomize: true,\n}\n\n// For all requests on a specific connection\nconnection.retry_opts = OPTS\nconnection.callSamanageAPI(request, ref).then(...).catch(...)\n\n// For a particular request\nrequest.retry_opts = OPTS \nconnection.callSamanageAPI(request, ref).then(...).catch(...)\n```\n\n## Retrieval with filters\n```javascript\nvar get_incidents = SamanageAPI.get('incident')\nvar request = get_incidents(\n  new SamanageAPI.Filters().add({\n    sort_order: 'ASC',\n    sort_by: 'created_at',\n    created: ['2018-01-01','2018-01-02']\n  })\n)\nconnection.callSamanageAPI(...)\n```\n\n### Building filters\n```javascript\nvar get_incidents = SamanageAPI.get('incident')\nvar filters = new SamanageAPI.Filters().\n  sort_by('name').\n  sort_order(SamanageAPI.Filter.DESC).\n  between_dates('created','2018-01-01','2018-01-02').\n  per_page(100).\n  page(3)\nvar request = get_incidents(filters)\n```\n\n## Export with filters\n\n```javascript\nvar export_incidents = SamanageAPI.export('incident')\nconnection.callSamanageAPI(\n  export_incidents(\n    new SamanageAPI.Filters().between_dates('created','2017-01-01','2018-07-07')\n  )\n).then(function (result) {\n  /* Success:\n    result contains pagination info (how many incidents are there) but\n    does NOT contain the incidents' data. It is sent via email\n  */\n}).catch(function(error) {\n  // Failure\n})\n```\n\n## Update\n```javascript\nvar request = SamanageAPI.update('incident')(3, {\n  name:'opened with samanage-api-js library'\n})\n```\n\n## Create\n```javascript\nvar request = SamanageAPI.create('incident')({\n  name:'opened with samanage-api-js library'\n})\n```\n\n## List of all functions and constants\n\nSamanageAPI has built in help.\nOpen a new node console, and execute this:\n\n```javascript\nvar SamanageAPI = require('samanage-api')\nconsole.log(SamanageAPI.help)\nconsole.log(SamanageAPI.Filters.help)\nconsole.log(SamanageAPI.Connection.help)\n```\n\n## Getter objects\nGetter objects are promises to get all items of certain type that match a specific `SamanageAPI.Filter`.\nGetters are very convenient way of retrieving things like Itsm States or Users,\nbut may not be proper strategy for retrieving very large sets of items\n(e.g. all audit logs since start of time);\nCurrently there's no check on number of items which will cause a very long retrieval process so just go ahead and experiment\n\nGetters are defined like this:\n\n```javascript\n// promise to get all ITSM states:\nvar itsm_states = connection.getter('itsm_state')\n\n// promise to get all users created between certain dates\nvar users_filter = (new SamanageAPI.Filter()).between_dates('created','2017-01-01','2018-07-07')\nvar users = connection.getter('user', users_filter)\n\n// promise to get all comments of particular incident\nvar comments = connection.getter('comment', (new SamanageAPI.Filters()), 'incidents/' + incident.id)\n```\n\nExample: Do something after both users and itsm states are retrieved\n\n```javascript\nPromise.all([itsm_states, users]).then(\n  function([states, users]) {...}\n)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feetay%2Fsamanage-api-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feetay%2Fsamanage-api-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feetay%2Fsamanage-api-js/lists"}