JSFiddle - React, Tailwind, and code Playground

by eurica

HTML

<script src="http://eurica.github.io/pdjs/js/pdjs.js"></script>
<!-- 
This is a lightweight demo that lists who is the primary on call on the webdemo account (an internal PagerDuty demo account) for each of the esclation policies.

To configure it change the values in pdjs_settings below to your subdomain & api key.  Recommendation: Generate a new read-only API key to use in this script for testing.

This script uses jQuery and the unofficial PagerDuty JavaScript wrapper: https://github.com/eurica/pdjs
-->

JavaScript

// Authentication information for PagerDuty 
var pdjs_settings = {
    subdomain: "webdemo",
    token: "CkNpsqH9i6yTGus8VDzA", // <- API Key
    // https://support.pagerduty.com/entries/23761081-Generating-an-API-Key
    // Recommendation: Generate a new read-only API key to use in this script for testing.
}

// My barebones UI :)
printf = function (s) {
    $("body").append(s)
}

// Hits the escalation_policies/on_call endpoint, then loops over the results
// http://developer.pagerduty.com/documentation/rest/escalation_policies/on_call
$(function () {
    PDJS = new PDJSobj(pdjs_settings)
    PDJS.api({
        res: "escalation_policies/on_call",
        success: function (data) {
            for (i in data.escalation_policies) {
                ep = data.escalation_policies[i]
                printf(ep.name + "<br>")
                for (j in ep.on_call) { // <- loop through all on-calls for this ep
                    u = ep.on_call[j]
                    if (u.level > 1) break; // <- only display the primaries
                    printf(" - <a href='mailto:" + u.user.email + "'>" + u.user.name + "</a><br>")
                }
            }
        }

    })


})