{"id":21050426,"url":"https://github.com/pagerduty/pdjs","last_synced_at":"2025-04-05T09:04:56.881Z","repository":{"id":8961114,"uuid":"10700658","full_name":"PagerDuty/pdjs","owner":"PagerDuty","description":"JavaScript wrapper for the PagerDuty API","archived":false,"fork":false,"pushed_at":"2024-11-01T19:03:36.000Z","size":1920,"stargazers_count":63,"open_issues_count":30,"forks_count":35,"subscribers_count":128,"default_branch":"main","last_synced_at":"2025-03-29T08:03:20.968Z","etag":null,"topics":["category-distributed","renovate-enabled","team-developer-foundations"],"latest_commit_sha":null,"homepage":"http://developer.pagerduty.com/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PagerDuty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-15T01:18:50.000Z","updated_at":"2025-03-05T23:46:24.000Z","dependencies_parsed_at":"2024-06-06T21:01:40.631Z","dependency_job_id":"4fdd4f31-d821-45d7-9119-c443ccd4b4fe","html_url":"https://github.com/PagerDuty/pdjs","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PagerDuty%2Fpdjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PagerDuty%2Fpdjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PagerDuty%2Fpdjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PagerDuty%2Fpdjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PagerDuty","download_url":"https://codeload.github.com/PagerDuty/pdjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312077,"owners_count":20918344,"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":["category-distributed","renovate-enabled","team-developer-foundations"],"created_at":"2024-11-19T15:31:07.297Z","updated_at":"2025-04-05T09:04:56.848Z","avatar_url":"https://github.com/PagerDuty.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README\n\nA simple JavaScript wrapper for the PagerDuty APIs.\n\n- Supports Node and Browser environments\n- Supports REST and Events v2 APIs.\n- Supports both offset and cursor based pagination\n\nFor full [API Reference see this page.](https://developer.pagerduty.com/api-reference)\n\n## Installation\n\n```bash\nnpm install --save @pagerduty/pdjs\n```\n\n## Usage\n\n### REST API\n\nREST API calls can be done using the convenience methods or by passing in a `url` or `endpoint`.\n\n#### Convenience Methods\n\nThere are some simple convience methods. `get()`, `post()`, `put()`, and `delete()`.\n\n```javascript\nimport {api} from '@pagerduty/pdjs';\n\nconst pd = api({token: 'someToken1234567890'});\n\npd.get('/incidents')\n  .then({data, resource, next} =\u003e console.log(data, resource, next))\n  .catch(console.error);\n\n// Similarly, for `post`, `put`, `patch` and `delete`.\npd.post('/incidents', { data: { ... } }).then(...);\n\n// If you need to supply headers:\npd.post('/incidents/id/status_updates', {\n  headers: {\n    From: 'user@example.com',\n  },\n  data: { ... },\n}).then();\n```\n\n#### `tokenType`\n\nAllows you to set either `token` or `bearer` tokens. Defaults to `token` but provides ability to use `bearer` as well.\n\n- [Tokens](https://developer.pagerduty.com/docs/rest-api-v2/authentication/) are generated in your PagerDuty account.\n- **Bearer** tokens are generated through an [OAuth 2.0](https://developer.pagerduty.com/docs/app-integration-development/oauth-2-functionality/) authorization flow. For example, to use a Bearer token when initializing `api` you'll pass int the `tokenType` parameter, like so:\n\n```javascript\nconst pd = api({token: 'someBearerToken1234567890', tokenType: 'bearer'});\n```\n\n#### `url` or `endpoint`\n\n```javascript\n// Calling the returned function with a `endpoint` or `url` will also send it.\npd({\n  method: 'post',\n  endpoint: '/incidents',\n  data: {\n    ...\n  }\n}).then(...)\n```\n\n#### The Response Object\n\nThe PD object always returns an APIResponse object which contains some raw data as well as a convenient shortcut to directly access the returns Resource.\n\n```javascript\n\npd.get('/incidents')\n  .then({resource, data, response, next} =\u003e {\n    console.log(resource); // Contains the data of resource request. In this example the 'incidents' data.\n    console.log(data);     // The raw data returned from the API, also contains pagination information.\n    console.log(response); // The response object returned from the cross-fetch\n    console.log(next);     // A convenience function to help with pagination\n  })\n  .catch(console.error);\n\n```\n\n#### Pagination\n\nThere's an convience method `all` that attempts to fetch all pages for a given endpoint and set of parameters. For convenience this function supports both offset and cursor based pagination.\n\nNote that the PagerDuty API has a limit for most endpoints and recommends using parameters to refine searches where more results are necessary. More information can be found in the [Developer Documentation.](https://developer.pagerduty.com/docs/rest-api-v2/pagination/)\n\nThe response object of an API call also contains a `nextFunc` which can be used to define your own Pagination function if you feel included.\n\n```javascript\nimport {api} from '@pagerduty/pdjs';\n\nconst pd = api({token: 'someToken1234567890'});\n\npd.all('/incidents')\n  .then({data, resource} =\u003e console.log(data, resource))\n  .catch(console.error);\n```\n\n#### Options\n\nThe API interface allows for some extra parameters to be included.\n\n##### `server`\n\nTo use this library with a different service region use this parameter to change the root url of requests. Default: `api.pagerduty.com`. \n\n```javascript\npd({\n  method: 'post',\n  endpoint: '/incidents',\n  server: 'api.eu.pagerduty.com',\n  data: {\n    ...\n  }\n}).then(...)\n```\n\n##### `headers`\n\nSome endpoints require the setting of extra `headers` such as a `From` header.\n\n```javascript\npd({\n  method: 'post',\n  endpoint: '/incidents',\n  headers: {\n    'From': \"me@example.com\"\n  },\n  data: {\n    ...\n  }\n}).then(...)\n```\n\n### Retries\n\nThere is some very simple retry logic baked into each request in the case that the PagerDuty API rate limits your requests (only when it responds HTTP Code 429). Requests will retry 3 times waiting 20 seconds between each request. If the request is still being rate limited after 3 attempts the client will simply return the 429 response.\n\n### Events API\n\nEvents V2 is supported along with Change Events.\n\n```javascript\nimport {event} from '@pagerduty/pdjs';\nevent({\n  data: {\n    routing_key: 'YOUR_ROUTING_KEY',\n    event_action: 'trigger',\n    dedup_key: 'test_incident_2_88f520',\n    payload: {\n      summary: 'Test Event V2',\n      source: 'test-source',\n      severity: 'error',\n    },\n  },\n})\n  .then(console.log)\n  .catch(console.error);\n```\n\n#### Convenience Methods\n\n```javascript\nimport {change, trigger, acknowledge, resolve} from '@pagerduty/pdjs';\n\nchange({\n    \"routing_key\": \"YOUR_ROUTING_KEY\",\n    \"payload\": {\n      \"summary\": \"Build Success:!\",\n      \"timestamp\": \"2015-07-17T08:42:58.315+0000\",\n      \"source\": \"prod-build-agent\",\n      \"custom_details\": {\n        \"build_state\": \"passed\",\n        \"build_number\": \"220\",\n        \"run_time\": \"1337s\"\n      }\n    },\n    \"links\": [{\n      \"href\": \"https://buildpipeline.com\",\n      \"text\": \"View in Build Pipeline\"\n    }]\n})\n  .then(console.log)\n  .catch(console.error);\n\ntrigger({...})\n  .then(console.log)\n  .catch(console.error);\nacknowledge({...})\n  .then(console.log)\n  .catch(console.error);\nresolve({...})\n  .then(console.log)\n  .catch(console.error);\n```\n\n### Browser\n\nTwo browser-ready scripts are provided:\n\n- [dist/pdjs.js](https://raw.githubusercontent.com/PagerDuty/pdjs/main/dist/pdjs.js): For browsers supporting `fetch`.\n- [dist/pdjs-legacy.js](https://raw.githubusercontent.com/PagerDuty/pdjs/main/dist/pdjs-legacy.js): For older browsers requiring a `fetch` polyfill -- mostly IE 11.\n\nEither of these files can be used by copying them into your project and including them directly, with all functions namespaced `PagerDuty`:\n\n```html\n\u003cscript src=\"https://raw.githubusercontent.com/PagerDuty/pdjs/main/dist/pdjs.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  PagerDuty.api({token: 'someToken1234567890', endpoint: '/incidents'})\n    .then(response =\u003e console.log(response.data))\n    .catch(console.error);\n\u003c/script\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagerduty%2Fpdjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpagerduty%2Fpdjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagerduty%2Fpdjs/lists"}