Testing the Asana API with a personal access token
Asana's API is a clean REST API with two habits to learn: every response is wrapped in data, and by default you get only a few fields back. Ask for the fields you want with opt_fields, and the rest is ordinary REST testing.
Step 1: Token and environment
In Asana, My settings ▸ Apps ▸ Developer apps ▸ Create new token. Use a test workspace or a project nobody else watches.
| Variable | Value |
|---|---|
baseUrl | https://app.asana.com/api/1.0 |
asanaToken | the token, marked as secret |
projectGid | the id of a test project (from its URL) |
Authorization: Bearer token with {{asanaToken}}.
Step 2: Me and my workspaces
GET {{baseUrl}}/users/me?opt_fields=name,email,workspaces.nameconst me = pm.response.json().data;
pm.test('token works', () => pm.expect(me.gid).to.be.ok);
pm.environment.set('workspaceGid', me.workspaces[0].gid);Asana ids are called gid and are strings. Keep them as strings; some are too large for a JavaScript number anyway.
Step 3: Create a task
POST {{baseUrl}}/tasks?opt_fields=name,completed,projects.name,due_on
Content-Type: application/json
{"data": {"name": "API test {{$timestamp}}", "projects": ["{{projectGid}}"], "due_on": "2026-12-31", "notes": "Created by API tests"}}const task = pm.response.json().data;
pm.test('task created', () => {
pm.expect(pm.response.code).to.equal(201);
pm.expect(task.completed).to.equal(false);
pm.expect(task.due_on).to.equal('2026-12-31');
});
pm.environment.set('taskGid', task.gid);Forgetting the data wrapper is the most common mistake here: Asana answers 400 with "missing data" or ignores the fields.
Step 4: Complete it
PUT {{baseUrl}}/tasks/{{taskGid}}
Content-Type: application/json
{"data": {"completed": true}}pm.test('completed', () => pm.expect(pm.response.json().data.completed).to.equal(true));Step 5: Pagination
GET {{baseUrl}}/projects/{{projectGid}}/tasks?limit=100&opt_fields=name,completedconst next = pm.response.json().next_page;
if (next) pm.environment.set('offset', next.offset);Pass &offset={{offset}} for the next page. Without limit, some list endpoints return everything at once, and on a large project that's slow or refused, so always set it.
Step 6: Errors
// "Get a task that doesn't exist": expected failure
pm.test('not found', () => {
pm.expect(pm.response.code).to.equal(404);
pm.expect(pm.response.json().errors[0].message).to.be.a('string');
});| Status | Cause |
|---|---|
400 | invalid body, often the missing data wrapper |
401 | bad token |
403 | the token's user can't see that workspace or project |
404 | wrong gid, or no access |
429 | rate limited; Retry-After says how long |
Delete the task in a cleanup step with DELETE {{baseUrl}}/tasks/{{taskGid}}.