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

SendGrid Email Activity API query #1082

Open
gmparker2000 opened this issue Jun 20, 2024 · 0 comments
Open

SendGrid Email Activity API query #1082

gmparker2000 opened this issue Jun 20, 2024 · 0 comments

Comments

@gmparker2000
Copy link

I am trying to use the SendGrid email activity API to retrieve a list activities from a celery task in python. I'm using the sendgrid library version 6.11.0 (https://pypi.org/project/sendgrid/). I would like the task to run nightly and retrieve activities between the last time the task ran and the current time. It appears that you should be able to use a query parameter that specifies the two dates (https://www.twilio.com/docs/sendgrid/for-developers/sending-email/getting-started-email-activity-api). So I tried the following:

from sendgrid import SendGridAPIClient

sg_client = SendGridAPIClient(self._api_key)

start_time = '2024-06-19T00:00:00Z'
end_time = '2024-06-19T23:59:59Z'
response = sg_client.client.messages.get(query_params={
            'limit': 100000,
            'last_event_time': 'BETWEEN TIMESTAMP ' + start_time + ' AND TIMESTAMP ' + end_time,
        })

This does return messages, but includes messages outside the dates specified. I also tried url encoding the last_event_time value with and without quotes around the start and end times (and many other variations) with no success. On a positive note, I ran the command using Curl and it worked.

Additionally, notice the large limit parameter. It seems that limit is required but there is no offset parameter. I have no idea how many messages exist between the two dates. How can I know if I've retrieved them all? If I ask for 100 and less than 100 are returned I could assume I'm done. If I ask for 100 and get 100 then there are probably more. But without an offset parameter how can I retrieve them? I also did not see the maximum limit documented anywhere.

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

No branches or pull requests

1 participant