Google-api-nodejs-client: Gmail API - Users.messages: list - Query Parameters are Ignored

Created on 26 Jan 2018  ·  3Comments  ·  Source: googleapis/google-api-nodejs-client

The optional query parameters for Gmail API documented in Users.messages: list are ignored.

Parameter name | Value | Description
-- | -- | --
labelIds[] | list | Only return messages with labels that match all of the specified label IDs.
maxResults | unsigned integer | Maximum number of messages to return.
q | string | Only return messages matching the specified query.

code sample

  var gmail = google.gmail({auth: auth, version: 'v1'});
  gmail.users.messages.list({
    userId: 'me',
    maxResults: 1,
  }, function(err, res) {
    if (err) {
      console.log('The Gmail API returned an error: ' + err);
      return;
    }

    console.log(res);
  });

The call in the code above should return 1 result at max, but it returns all the messages in the mailbox. The same happens when a query is specified.

response

{ messages:
   [ { id: '16131b7e5a488eb9', threadId: '16131b7e5a488eb9' },
     { id: '161319d1e0c917af', threadId: '161319d1e0c917af' },
     { id: '1612912289991e74', threadId: '16128fd9e7655471' },
     { id: '161290d11a50009e', threadId: '16128fd9e7655471' },
     { id: '1612900d9a5df770', threadId: '16128fd9e7655471' },
     { id: '16129004fca053e2', threadId: '16128fd9e7655471' },
     { id: '16128fd9e7655471', threadId: '16128fd9e7655471' },
     { id: '16128fc7d97d6049', threadId: '16128fc7d97d6049' },
     { id: '16128fabc94fe685', threadId: '16128fabc94fe685' },
     { id: '16128f82f1d4d3fb', threadId: '161286d6171b21f1' },
     { id: '16128aeef1688860', threadId: '161286d6171b21f1' },
     { id: '16128958649ef891', threadId: '161286d6171b21f1' },
     { id: '161287d74e632878', threadId: '161286d6171b21f1' },
     { id: '161286fcac8f3e73', threadId: '161286d6171b21f1' },
     { id: '161286f1986ce753', threadId: '161286d6171b21f1' },
     { id: '161286d6171b21f1', threadId: '161286d6171b21f1' },
     { id: '161285a266fc1f67', threadId: '161285a266fc1f67' },
     { id: '161285a26134f582', threadId: '161285a26134f582' },
     { id: '16128514fe319d49', threadId: '16128514fe319d49' },
     { id: '1612850eb42ef951', threadId: '1612850eb42ef951' },
     { id: '1612850e9a6b051e', threadId: '1612850e9a6b051e' } ],
  resultSizeEstimate: 21 }

npm package version
└── [email protected]

Most helpful comment

Check #469 issue, it seems the same problem

All 3 comments

Check #469 issue, it seems the same problem

@inacior Thanks!! I did what bartman did in #469 to set the query parameter manually and it worked.

Greetings folks! Please check your package.json. Are you installing both googleapis and google-auth-library? For a while our docs suggested to do this, but it is very wrong. You should make sure you're only installing googleapis, and following this sample:
https://github.com/google/google-api-nodejs-client/blob/master/samples/gmail/list.js

Can you verify any of this?

Was this page helpful?
0 / 5 - 0 ratings