Back to APIs

Manage your DigitalOcean resources, storage, and compute resources.

Using the DigitalOcean API with Trigger.dev

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

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

Example code using DigitalOcean

Below is a working code example of how you can use DigitalOcean 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
// API reference: https://docs.digitalocean.com/reference/api/api-reference/#operation/uptime_create_check
5
// Create tokens at
6
// https://docs.digitalocean.com/reference/api/create-personal-access-token/
7
8
const endpointURL = "https://api.digitalocean.com/v2/uptime/checks";
9
10
client.defineJob({
11
id: "digitalocean",
12
name: "DigitalOcean uptime create",
13
version: "1.0.0",
14
trigger: eventTrigger({
15
name: "digitalocean",
16
schema: z.object({
17
name: z.string(),
18
type: z.enum(["http", "https", "ping"]).default("https"),
19
target: z.string(),
20
regions: z.string().array().default(["us_east", "eu_west"]),
21
enabled: z.boolean().default(true),
22
}),
23
}),
24
run: async (payload, io, ctx) => {
25
// Wrap an SDK call in io.runTask so it's resumable and displays in logs
26
await io.runTask(
27
"DigitalOcean",
28
async () => {
29
// Make request using Fetch API
30
return await fetch(endpointURL, {
31
method: "POST",
32
headers: {
33
Authorization: `Bearer ${process.env.DIGITALOCEAN_TOKEN}`,
34
"content-type": "application/json",
35
},
36
body: JSON.stringify(payload),
37
}).then((response) => response.json());
38
},
39
40
// Add metadata to improve how the task displays in the logs
41
{ name: "DigitalOcean uptime create", icon: "digitalocean" }
42
);
43
},
44
});