Back to APIs

List, create, update and delete applications.

Using the Svix API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Svix 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 Svix

Below are some working code examples of how you can use Svix 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 { Webhook } from "svix";
2
import { TriggerClient } from "@trigger.dev/sdk";
3
4
// Go to dashboard.svix.com > Operational Webhooks
5
// Create an endpoint with the Webhook URL
6
// Obtain the Signing Secret from the right
7
// To trigger the webhook, Testing > Send Event > Send Example
8
const svix = client.defineHttpEndpoint({
9
id: "svix",
10
source: "svix.com",
11
icon: "svix",
12
verify: async (request) => {
13
const body = await request.text();
14
const svixID = request.headers.get("svix-id");
15
const svixTimestamp = request.headers.get("svix-timestamp");
16
const svixSignature = request.headers.get("svix-signature");
17
if (!svixID || !svixTimestamp || !svixSignature) {
18
return { success: false, reason: "Svix headers are missing" };
19
}
20
const headers = {
21
"svix-id": svixID,
22
"svix-timestamp": svixTimestamp,
23
"svix-signature": svixSignature,
24
};
25
const wh = new Webhook(process.env.SVIX_SECRET_KEY!);
26
try {
27
// Below throws an error if not matching, hence put in try/catch
28
wh.verify(body, headers);
29
return { success: true };
30
} catch (e) {
31
console.log(e);
32
return {
33
success: false,
34
reason:
35
"Svix verification failed due to " + (e.message || e.toString()),
36
};
37
}
38
},
39
});
40
41
client.defineJob({
42
id: "http-svix",
43
name: "HTTP Svix",
44
version: "1.0.0",
45
enabled: true,
46
trigger: svix.onRequest(),
47
run: async (request, io, ctx) => {
48
const body = await request.json();
49
await io.logger.info(`Body`, body);
50
},
51
});