Python Events


#1

Hello. I’m trying to use the Python client library for Asana API to listen for events on projects and react to task ‘added’ events.

Background: A user completes a request via Microsoft Forms. Forms connects to Asana via an Asana connector. All data from the form is copied to the Notes section of the task.

Current: I wrote a Python program to connect to Asana, find new tasks, parse the Notes data, and move that data into appropriate custom fields. This program has been scheduled via Task Scheduler on Windows to run every 15 minutes. It works fine.

Next Step: I’d like to modify the Python program to listen for task ‘added’ events on a number of projects, and update the tasks as needed. When I try to make an initial GET request to Events with Python, an Exception is raised (asana.error.InvalidTokenError) and no sync token is issued. If I make the same request via curl, I see the sync token.

try: 
  client.events.get({ 'resource': pycProjectId })
except asana.error.InvalidTokenError as e:
  print(e)

Sync token invalid or too old: Sync token invalid or too old. If you are attempting to keep resources in sync, you must fetch the full dataset for this query now and use the new sync token for the next sync.

Maybe I am going about this the wrong way? Any advice would be appreciated.

Thanks!


#2

I think you’re actually on the right track. The error is to be expected the first time you call the events endpoint. See this post for more info:


#3

Thanks for your response, Phil. I’m unable to work with Events.get() (the response is missing a sync token), but Events.get_next() works as I would expect, so I’m using that and it seems to work well.