Gmail API all messages

imCaps picture imCaps · Jul 9, 2014 · Viewed 8k times · Source

I need to get all messages in Inbox with gmail api. But I see only one way to do it.

  1. Get list of messages(id, threadID)

    GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages?labelIds=INBOX&key={YOUR_API_KEY}
    
  2. With id`s get all messages in loop

    While 
        GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages/147199d21bbaf5a5?key={YOUR_API_KEY}
    End of While
    

But for this way needed 100500 request. Have anybody idea how to get with one request all messages(or just payload field)?

Answer

Eric D picture Eric D · Jul 9, 2014

Use batch and request 100 messages at a time. You will need to make 1000 requests but the good news is that's quite fine and it'll be easier for everyone (no downloading 1GB response in a single request!).

Documented at: https://developers.google.com/gmail/api/guides/batch

There's a few other people that have asked about batching Gmail Api here on Stack Overflow, so just do a quick search to find answers and examples.