Skip to content

How to receive next sync token using EventsApi#get_events #199

Open

Description

@trunneml

Your example only shows how to receive events when we already have the sync token.
But atleast your example does not provide the new sync token for the next call.

import asana
from asana.rest import ApiException
from pprint import pprint

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
events_api_instance = asana.EventsApi(api_client)
resource = "12345" # str | A resource ID to subscribe to. The resource can be a task, project, or goal.
opts = {
    'sync': "de4774f6915eae04714ca93bb2f5ee81", # str | A sync token received from the last request, or none on first sync. Events will be returned from the point in time that the sync token was generated. *Note: On your first request, omit the sync token. The response will be the same as for an expired sync token, and will include a new valid sync token.If the sync token is too old (which may happen from time to time) the API will return a `412 Precondition Failed` error, and include a fresh sync token in the response.*
    'opt_fields': "action,change,change.action,change.added_value,change.field,change.new_value,change.removed_value,created_at,parent,parent.name,resource,resource.name,type,user,user.name", # list[str] | This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include.
}

try:
    # Get events on a resource
    api_response = events_api_instance.get_events(resource, opts)
    for data in api_response:
        pprint(data)
except ApiException as e:
    print("Exception when calling EventsApi->get_events: %s\n" % e)

Without the sync token this part of the API is not that helpful.

Activity

  1. trunneml commented on Jul 24, 2024

    @trunneml
    Author

    I think removing .items() and returning the full EventIterator in

    should fix this problem. But this would be a breaking API change.

  2. jv-asana commented on Jul 29, 2024

    @jv-asana
    Contributor

    Hi @trunneml,

    See my comment for a workaround here. Thanks for pointing this out. I think it's probably best for us not to try to auto paginate our events endpoint and let users handle how they want to call our events endpoint.

    The problem with auto paginating our events endpoint is we have to decide when to stop the iteration. So we could either stop the iteration when the Asana API returns has_more is false OR keep calling the next sync token making the get_events method turn into an event stream where it constantly fetches and watches for new events. If we go with the event stream approach we'll need to add some kind of delay otherwise it'll hit the Asana API rate limits.

    What's your use case with our events endpoint? And how would you prefer this endpoint behaves for python?

  3. tarensanders commented on Nov 12, 2025

    @tarensanders

    Just want to chime in that this issue is >12m old, and means that the (otherwise pretty good) API docs lead you down entirely the wrong path.

    My use case is that I need to keep two systems in sync, but not in real time. I also don't have an always up server to receive a webhook. Polling the resource and only running a full sync when there are events seems like a reasonable use case, but the current docs make it so unclear how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions