Back to APIs

Integrate and automate code security and scan for vulnerabilities.

Using the Snyk API with Trigger.dev

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

Below are some working code examples of how you can use Snyk 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, verifyRequestSignature } from "@trigger.dev/sdk";
2
3
// Create an HTTP endpoint to listen to Snyk webhooks
4
// (This will create the endpoint URL & Secret on the `trigger.dev` dashboard)
5
// Create a Snyk webhook by providing the endpoint URL & Secret (Copy from the dashboard) in the request body.
6
// Use https://snyk.docs.apiary.io/#reference/webhooks/webhook-collection/create-a-webhook?console=1
7
// Set the `SNYK_WEBHOOK_SIGNING_SECRET` (Secret) in the .env file.
8
const snyk = client.defineHttpEndpoint({
9
id: "snyk",
10
source: "snyk.com",
11
icon: "snyk",
12
verify: async (request) => {
13
return await verifyRequestSignature({
14
request,
15
headerName: "x-hub-signature",
16
secret: process.env.SNYK_WEBHOOK_SIGNING_SECRET!,
17
algorithm: "sha256",
18
});
19
},
20
});
21
22
client.defineJob({
23
id: "http-snyk",
24
name: "HTTP Snyk",
25
version: "1.0.0",
26
enabled: true,
27
trigger: snyk.onRequest(),
28
run: async (request, io, ctx) => {
29
const body = await request.json();
30
await io.logger.info(`Body`, body);
31
},
32
});