Back to APIs

Manage incidents, schedules, and more with PagerDuty.

Using the PagerDuty API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your PagerDuty background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using PagerDuty

Below are some working code examples of how you can use PagerDuty with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import crypto from "crypto";
2
import { TriggerClient } from "@trigger.dev/sdk";
3
4
// Create an HTTP endpoint to listen to PagerDuty webhooks.
5
// (This will create the endpoint URL on the `trigger.dev` dashboard)
6
// Create a PagerDuty account (if you don't have one).
7
// Go to Integrations -> Generic Webhooks and setup the subscription.
8
// Copy the secret shown in popup to PAGERDUTY_WEBHOOK_SIGNING_SECRET in the .env file.
9
const pagerduty = client.defineHttpEndpoint({
10
id: "pagerduty",
11
source: "pagerduty.com",
12
icon: "pagerduty",
13
verify: async (request) => {
14
const bodyText = await request.text();
15
const signatures = request.headers.get("X-PagerDuty-Signature");
16
if (!signatures) {
17
return { success: false };
18
}
19
const signature = crypto
20
.createHmac("sha256", process.env.PAGERDUTY_WEBHOOK_SIGNING_SECRET!)
21
.update(bodyText)
22
.digest("hex");
23
const signatureWithVersion = "v1=" + signature;
24
const signatureList = signatures.split(",");
25
return {
26
success: signatureList.indexOf(signatureWithVersion) > -1,
27
};
28
},
29
});
30
31
client.defineJob({
32
id: "http-pagerduty",
33
name: "HTTP PagerDuty",
34
version: "1.0.0",
35
enabled: true,
36
trigger: pagerduty.onRequest(),
37
run: async (request, io, ctx) => {
38
const body = await request.json();
39
await io.logger.info(`Body`, body);
40
},
41
});