Search code examples
gmail-apigoogle-apis-explorer

Why does gmail API when using history.list method send message ids without the field what action has been preformed on them?


When using gmail API, history.list method we get "bare" message ids with no additional field from the fields in 'labelAdded', 'labelRemoved', 'messageAdded', 'messageRemoved'. Why is that? And is it possible that a new message has been added but when we use this method, the field messageAdded hasn't been used, so we receive it "bare" ?


Solution

  • According to the GMail history API, the list only contains the id and threadId fields.
    It works this way because the objective of the history API is to provide you with the changes that happened in the mailbox, not its contents.

    After you obtain the list from Users.history: list you need to call Users.messages: get or Users.messages: list to get the full messages.

    If the messageAdded field is empty, it means that no new messages were added after the last historyId you examined. You might have skipped some. Make sure that every time you query the API you internally store the last historyId you processed so you can resume from that point in the future and not lose any changes.