JSFiddle - React, Tailwind, and code Playground
HTML
<!--
To use this example, generate a v2 API key in your PagerDuty account
and update lines 1 and 2 with your API key and the escalation_policy_ids
-->
<h1>Who's on call for our team</h1>
<pre id="raw_output"></pre>
CSS
#raw_output {
display: none;
}
JavaScript
api_key = "jeZuiVYQbpG8dsz7uw7W"
escalation_policies = "escalation_policies?team_ids%5B%5D=PBSU8DD"
$.ajax({
headers: {
Accept: "application/vnd.pagerduty+json;version=2",
Authorization: "Token token="+api_key
},
url: "https://api.pagerduty.com/oncalls?time_zone=UTC&"+escalation_policies,
cache: false,
success: function(json) {
display_oncall(json)
console.log(json);
//You'll probably want to remove this:
$("#raw_output").append(JSON.stringify(json, null, ' '))
},
error: function(data) {
alert("Error")
console.log(data)
}
})
function display_oncall(json) {
console.log("Displaying")
console.log(json)
$.each(json.oncalls, function(index, value ){
console.log(index)
console.log(value)
if(value.escalation_level == 1) {
$('body').append("<div><a href='"+value.user.html_url+"'>"+value.user.summary+" is on call for "+value.escalation_policy.summary+" (level "+value.escalation_level+")</div>")
}
})
}