Add webhooks to every PagerDuty service

Add a webhook to every service within a PagerDuty account

by Ryan Hoskin

HTML

<script src="https://eurica.github.io/pdjs/js/pdjs.js"></script>

JavaScript

//Add a webhook to every service within a PagerDuty account
PDJS = new PDJSobj({
    subdomain: "pdt-ryan",
    token: "ZPypwtpDgXPyq9p97dk5",
});

create_webhook = function(service_id) {
    PDJS.api({
        res: "webhooks",
        type: "POST",
        data: {
            webhook_object: {
                id: service_id,
                type: "service",
                object: {
                    id: service_id,
                    type: "service"
                }
            },
            name: "Webhook Name 2",
            url: "https://enter_the_new_url2.com"
        },
        success: function(json) {
            console.log(json)
        }
    })
}

PDJS.api_all({
    res: "services",
    final_success: function (data) {
        jQuery.each(data.services, function (index, service) {
            create_webhook(service.id)
        })
    }
});