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, eventTrigger } from "@trigger.dev/sdk";
2
import { z } from "zod";
3
4
const asana = require("asana");
5
6
// Create a personal access token: https://developers.asana.com/docs/personal-access-token
7
const asanaClient = asana.Client.create().useAccessToken(
8
process.env.ASANA_ACCESS_TOKEN
9
);
10
11
client.defineJob({
12
id: "asana-get-user",
13
name: "Asana Get User",
14
version: "1.0.0",
15
trigger: eventTrigger({
16
name: "asana.get.user",
17
schema: z.object({
18
// This can either be the string "me", an email, or the GID of a user.
19
// You can get your user GID by first logging in to Asana in your browser,
20
// then visiting https://app.asana.com/api/1.0/users/me.
21
userGid: z.string(),
22
}),
23
}),
24
25
run: async (payload, io, ctx) => {
26
// Wrap an SDK call in io.runTask so it's resumable and displays in logs
27
const user = await io.runTask(
28
"Get user",
29
async () => {
30
// This is the regular Asana SDK
31
return asanaClient.users.getUser(payload.userGid);
32
},
33
34
// Add metadata to improve how the task displays in the logs
35
{ name: "Get Asana User", icon: "asana" }
36
);
37
},
38
});