How to get task events without storing sync token for each project?

I’m writing a program that will run every 5 minutes, with the idea that it will check if any new tasks have been completed in that time frame, look into the details of that task, then execute further actions if certain conditions in the task notes are true. From my understanding, I must read the events log of each individual project to see any activity with the tasks in that project. I thought this wouldn’t be a problem, I could just loop through all the projects and read their events, not the quickest method, but manageable… that is until I realized this meant storing individual sync tokens for every project, and that poses an issue.

Originally I wanted to set this up as a webhook to listen for task completion across the workspace, but in reading about establishing webhooks in Asana I found that since I’m writing my code in Google Apps Script I can’t complete the handshake part of the webhook creation. In reading forums I came to the conclusion that events are just as effective.

If events are not the best way to do this, what should my alternative be? If events are the best route to take, is there a more streamlined way to check for recently completed tasks across all 75-100 projects in my workspace? Or do I really just need to store all of those sync tokens somewhere, creating and removing them as projects are added and deleted to/from our workspace?

Thanks in advance for any and all help!

Hi,

I am a bit confused by your statement, I don’t know what’s a token for a project. In Asana, you can generate a Personal Access Token, but this gives you access to any project your account has access to, it is not specific to a project.

Or maybe this is related to the Event part of the API, which I don’t know enough. @Phil_Seeman any idea?

Thanks

Sync tokens are what I’m referring to, which are associated with events, yes. The token that is generated each time an event is pulled which is then used as a parameter for the next event API pull as a reference point to get events since the time that token was generated.

Thanks

1 Like

I think the best method you can use to achieve your goal, is to query tasks that have been modified since (last time), that are completed, using the Search API.

example:
GET /workspaces/{workspace_gid}/tasks/search?modified_at.after=2023-02-07T14:40:00Z&completed=1&limit=100

OR
GET /workspaces/{workspace_gid}/tasks/search?completed_at.after=2023-02-07T14:40:00Z&limit=100

Just, watch out for paging if you get more than 100 results, as it’s not working the same way normal endpoint works.

1 Like

This is it! This is what I’m looking for! Thank you very much for your help.

1 Like