question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding label to gmail message.

See original GitHub issue

Every request I make to users.messages.modify (https://developers.google.com/gmail/api/v1/reference/users/messages/modify) returns:

{ errors:
    [ { domain: 'global',
        reason: 'invalidArgument',
        message: 'No label add or removes specified' } ],
   code: 400,
   message: 'No label add or removes specified' }

I am making the request like:

var service = Google.gmail({version : 'v1', auth : oauth2Client});
service.users.messages.modify({
    'userId': 'some email address',
    'id': 'some message id',
    'addLabelIds': ['some label id'],
    'removeLabelIds': []
}, function (err) {
    if (!err) {
        callback(true);
    } else {
        console.log(err);
        callback(false);
    }
});

Not sure if I am just missing something or if this is an issue with the library.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
eweincommented, Aug 25, 2021

I solved it. The problem is you have to pass the addLabelIds parameter inside a resource object:

var service = Google.gmail({version : 'v1', auth : oauth2Client});
service.users.messages.modify({
    'userId': 'some email address',
    'id': 'some message id',
    'resource':{
        'addLabelIds': ['some label id'],
        'removeLabelIds': []
    }
}, function (err) {
    if (!err) {
        callback(true);
    } else {
        console.log(err);
        callback(false);
    }
});

The docs only say “In the request body, supply data with the following structure:”

{
  "addLabelIds": [
    string
  ],
  "removeLabelIds": [
    string
  ]
}

They don’t say anything about a resource object. Same goes for the users.labels.create function it says to put the request body in a label object but this library actually only takes a resource object.

12reactions
Roilancommented, Jun 8, 2016

Doc still hasn’t been updated 😦

Spent time trying to figure out what was wrong before I came across this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create labels to organize Gmail - Android - Google Support
On your Android phone or tablet, open the Gmail app . Open a message. ... Tap Change labels. Add or remove labels. Tap...
Read more >
How to Add Labels in Gmail to Categorize Your Emails
1. Open the Gmail app on your phone or tablet. 2. Navigate to the message you'd like to label. 3. Tap the three...
Read more >
How to Use Gmail Labels (Step-by-Step Guide w/ Screenshots)
Select the email message or messages you want to label from your Gmail inbox and click the label button (or label icon) located...
Read more >
How to create labels in Gmail - Android Police
From the main Gmail menu ; Select the + icon. add-new-label-1 ; Click Create, and the new Gmail label is ready to use....
Read more >
How To Automatically Label E-mails in Gmail - Alphr
Automatically label emails in Gmail · Select Create Label from the left menu. · Name your new label something meaningful and select Create....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found