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 { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import z from "zod";
3
4
// Guide to create PagerDuty API key https://support.pagerduty.com/docs/api-access-keys
5
// Navigate to integrations > API Access Keys
6
// Click on "Create New API Key" and give it a description and click on "Create Key"
7
// Set the PAGERDUTY_API_KEY in the .env file.
8
const endpointURL = `${process.env.PAGERDUTY_BASE_URL}/addons`;
9
10
// Create request options
11
const requestOptions: RequestInit = {
12
method: "POST",
13
headers: {
14
Authorization: `Token ${process.env.PAGERDUTY_API_KEY}`,
15
"content-type": "application/json",
16
Accept: "application/vnd.pagerduty+json;version=2",
17
},
18
};
19
20
client.defineJob({
21
id: "pagerduty-install-addon",
22
name: "PagerDuty Install Addon",
23
version: "1.0.0",
24
trigger: eventTrigger({
25
name: "pagerduty-install-addon",
26
schema: z.object({
27
addon: z.object({
28
type: z.string(),
29
name: z.string(),
30
src: z.string(),
31
}),
32
}),
33
}),
34
run: async (payload, io, ctx) => {
35
const {
36
addon: { type, name, src },
37
} = payload;
38
39
// Wrap an SDK call in io.runTask so it's resumable and displays in logs
40
await io.runTask(
41
"PagerDuty Install Addon",
42
async () => {
43
// Make request using Fetch API
44
return await fetch(endpointURL, {
45
...requestOptions,
46
body: JSON.stringify({
47
type,
48
name,
49
src,
50
}),
51
}).then((response) => response.json());
52
},
53
54
// Add metadata to improve how the task displays in the logs
55
{ name: "PagerDuty Install Addon", icon: "pagerduty" }
56
);
57
},
58
});