Back to APIs

Subscribe to task changes, manage projects and more.

Using the Asana API with Trigger.dev

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

Below are some working code examples of how you can use Asana 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
const ASANA_SECRET_KEY = 'ASANA_SECRET';
4
5
// Create an HTTP endpoint to listen to Asana webhooks.
6
// (This will create the endpoint URL on the `trigger.dev` dashboard)
7
// Create a Asana webhook by providing the endpoint URL and interested resources/events.
8
// (use https://developers.asana.com/reference/createwebhook)
9
const asana = client.defineHttpEndpoint({
10
id: 'asana',
11
source: 'asana.com',
12
icon: 'asana',
13
// This is needed for the initial webhook handshake.
14
// https://developers.asana.com/docs/webhooks-guide#the-webhook-handshake
15
respondWith: {
16
skipTriggeringRuns: true,
17
filter: {
18
method: ['POST'],
19
headers: {
20
'x-hook-secret': [{ $startsWith: '' }],
21
},
22
},
23
handler: async (req, verify) => {
24
const secret = req.headers.get('x-hook-secret');
25
26
if (!secret) {
27
return new Response('Unauthorized', { status: 401 });
28
}
29
30
// Asana sends the Secret (used to sign webhooks) as part of the initial handshake.
31
// This is persisted in a KV store on `trigger.dev` (can be retrieved later).
32
await client.store.env.set(ASANA_SECRET_KEY, secret);
33
34
return new Response(undefined, {
35
status: 204,
36
headers: {
37
'x-hook-secret': secret,
38
},
39
});
40
},
41
},
42
verify: async request => {
43
// Retrive the stored Secret from KV store.
44
const secret = await client.store.env.get<string>(ASANA_SECRET_KEY);
45
46
if (!secret) {
47
return { success: false, reason: 'secret not found' };
48
}
49
50
return await verifyRequestSignature({
51
request,
52
headerName: 'X-Hook-Signature',
53
secret,
54
algorithm: 'sha256',
55
});
56
},
57
});
58
59
client.defineJob({
60
id: 'http-asana',
61
name: 'HTTP Asana',
62
version: '1.0.0',
63
enabled: true,
64
//create a trigger from the HTTP endpoint
65
trigger: asana.onRequest(),
66
run: async (request, io, ctx) => {
67
const body = await request.json();
68
await io.logger.info(`Body`, body);
69
},
70
});