I need to use a polling strategy (as opposed to webhooks) in order to sync emails into my app. I need to ensure that all emails to/from a contact are captured, including emails that have already been sent to TRASH (i.e. for Gmail). It appears that GET messages does not natively return any messages in TRASH. GET threads does include message id’s that are in trash. However, if I have to GET threads and then turn around and use a GET message for each and every message in each thread, the number of api calls is too much.
Is there any way to simply get all messages sent/received after a certain date (i.e. the last time a sync occurred) for a list of email addresses…including messages in TRASH?
Using these four requests you should be able to retrieve all the messages you’re interested in.
Also, you may be able to shrink this down to just two queries if you use the search_query_native parameter because I believe Gmail has an OR operator. See their native syntax docs here: Refine searches in Gmail - Computer - Gmail Help. And here is our full guide on using Nylas’ search_query_native: Searching with Nylas | Nylas Docs
Got it…thanks. In an effort to minimize the number of api calls (and make this applicable for all providers, not just Gmail), can you just confirm that the below approach is technically accurate:
GET /threads (which also includes TRASH) where a) batch list of emails (contacts) included in the any_email and b) last_message_after is > the last time we ran the GET /threads for that user and c) select=id
For each returned thread_id, run a GET /threads/[thread_id] and filter through the results for any new messages since last pull