Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trunneml opened this issue Jul 24, 2024 · 2 comments
Open

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

trunneml opened this issue Jul 24, 2024 · 2 comments

Comments

@trunneml
Copy link

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.

@trunneml
Copy link
Author

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

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

@jv-asana
Copy link
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?

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

No branches or pull requests

2 participants