Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
pagerduty-pdjs
Advanced tools
This is a simple client-side JavaScript wrapper to the PagerDuty API.
npm i pagerduty-pdjs
.PDJSobj
object, setting values for the subdomain
, token
, and api_version
fields on the object.var PDJS = new PDJSobj({
subdomain: 'webdemo',
token: 'rcgtBVpizBZQjDzE3Hub',
api_version: 'v1',
logging: true
});
subdomain
-- for this example we're using the webdemo
, but you would want to put in your subdomain.token
-- your API token. The one above is to provide read-only access to the webdemo
account. You can decide what kind of access your token will provide when you create it.api_version
-- By default, PDJS
uses version 2 of the PagerDuty REST and Events API. To request version 1, the api version needs to be specified here. The api_version parameter is optional.The most basic way to make an API call with PDJS
is to use the PDJS.api()
function.
PDJS.api({
res: 'services',
data: {
limit: 20,
},
success: function (data) {
console.log(data)
},
})
res
-- the API endpoint and path you're calling*data
-- the query-string parameters that can be appended to the endpoint. This parameter is optional.success
-- the callback function that is called when the API call completes successfully. This is required.error
-- the callback function that is called when there is an error with the API call. This parameter is optional, though recommended.*In additino to specififying the endpoint, the res
parameter may have an ID in it. For example, here's how to get the notes for an incident
with the ID of PNCII2E
.
PDJS.api({
res: 'incidents/PNCII2E/notes',
success: function (data) {
alert(JSON.stringify(data))
},
})
POST
and PUT
requests are also supported.
For instance, the following snippet adds a contact_method
for user: test@example.com
, and then adding a notification rule to alert that email address after 900 minutes:
add_contact_method = function(user_id) {
PDJS.api({
res: `users/${user_id}/contact_methods`,
type: 'POST',
data: {
contact_method: {
type:'email_contact_method',
address:'test4@example.com',
label: 'Added from PDJS',
}
},
success: function (data) {
console.log('New contact method ID: ' + data.contact_method.id)
add_notification_rule(user_id, data.contact_method, 900)
}
})
}
add_notification_rule = function(user_id, contact_method, start_delay_in_minutes) {
PDJS.api({
res: `users/${user_id}/notification_rules`,
type: 'POST',
data: {
notification_rule: {
type: "assignment_notification_rule",
contact_method: contact_method,
start_delay_in_minutes: start_delay_in_minutes,
urgency: "high"
}
},
success: function (data) {
console.log(data)
console.log('New notification rule ID: ' + data.notification_rule.id)
}
})
}
add_contact_method('PRJRF7T');
To see this code in action go to the add_contact_method example.
In addition to PDJS.api()
there's also PDJS.api_all()
which is a helper method that will handle limits and offsets for lists longer than 100 elements:
PDJS.api_all({
res: 'incidents',
data: {
since: '2013-08-01T09:53:17-07:00',
until: '2013-08-14T09:53:17-07:00',
status: 'resolved',
fields: 'incident_number,status,created_on,service'
},
final_success: function(data) {
console.log(data.total + ' objects!');
console.log(data);
},
incremental_success: function(data) {
console.log('Got data');
}
})
It works the same as PDJS.api()
, except you'll need to specify one or more of:
That's kind of nifty.
To get an idea for how PDJS
works, there's an examples directory:
PDJS
is written in CoffeeScript. To make changes to the library, you'll edit the coffee/pdjsbase.coffee
file and compile it by running the command below from the pdjs
directory to produce the JavaScript.
coffee --output js/pdjs.js --compile --watch coffee/
This project is for client-side JavaScript. If you're looking for a Node library, we recommend the node-pagerduty library.
Are you using this library or have questions? Let us know by posting to the PagerDuty Community Developer Forum.
You might notice that PDJS sends along some extra parameters, nothing scary, we use those to track QoS across our language-specific libraries.
FAQs
JavaScript wrapper for the PagerDuty API, maintained by PagerDuty
The npm package pagerduty-pdjs receives a total of 9 weekly downloads. As such, pagerduty-pdjs popularity was classified as not popular.
We found that pagerduty-pdjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.