1

I need to retrieve the number of all and unread emails per label. To my surprise the numbers retrieved by the API are different from the ones I see in my account.

var request = gapi.client.gmail.users.labels.get({
    'userId': 'me',
    'id': 'CATEGORY_UPDATES'
});


In Gmail:
10,789
7,408
From the API:
threadsTotal: 11,251
threadsUnread: 7,408
messagesTotal: 12,416
messagesUnread: 7,714

var request = gapi.client.gmail.users.labels.get({
    'userId': 'me',
    'id': 'CATEGORY_SOCIAL'
});


In Gmail:
10,468
10,114
From the API:
threadsTotal: 10,468
threadsUnread: 10,114
messagesTotal: 10,873
messagesUnread: 10,457


var request = gapi.client.gmail.users.labels.get({
    'userId': 'me',
    'id': 'CATEGORY_PERSONAL'
});

In Gmail:
8,270
2,374
From the API:
threadsTotal: 3,251
threadsUnread: 1,066
messagesTotal: 8,896
messagesUnread: 5,135

var request = gapi.client.gmail.users.labels.get({
    'userId': 'me',
    'id': 'CATEGORY_PROMOTIONS'
});


In Gmail:
22,079
21,251
From the API:
threadsTotal: 22,091
threadsUnread: 21,251
messagesTotal: 22,215
messagesUnread: 21,330

Why the difference?

erdomester
  • 11,789
  • 32
  • 132
  • 234

1 Answers1

0

As far as I know, one possible cause for the difference as discussed in Managing Labels is because of the many-to-many relationship with messages and threads wherein a single message or thread may have multiple labels applied to it and a single label may be applied to multiple messages or threads.

For this, you can try modifying the labels applied to a thread or you can modify which labels are associated with a message or thread to properly sort out your messages.

In addition to that, solutions given in this SO post - Why does search in gmail API return different result than search in gmail website? might also help.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22