Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gapi.client.gmail.users.labels.create gives invalidArgument error

I am working on creating labels using JavaScript Gmail API.

function createLabel(userId, newLabelName, callback) {
var request = gapi.client.gmail.users.labels.create({
'userId': userId,
'label': {'name': newLabelName}
});
request.execute(callback);}

This is the code of Developer API Example

I am able to authenticate and even I'll get the label list but while creating the label I am getting the below error.

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalidArgument",
    "message": "Invalid request"
   }
  ],
  "code": 400,
  "message": "Invalid request"
 }
}

But when I am using the Try It example It's working but only difference is it's do the POST request with key={Your auth key} which the example provided won't attach that part to URL.

like image 611
pixelbyaj Avatar asked May 23 '26 19:05

pixelbyaj


1 Answers

The data you send should be in the resource-parameter, and labelListVisibility and messageListVisibility are also mandatory fields:

function createLabel(userId, newLabelName, callback) {
  gapi.client.gmail.users.labels.create({
    userId: userId,
    resource: {
      name: newLabelName,
      labelListVisibility: 'labelShow',
      messageListVisibility: 'show'
    }
  }).execute(callback);
}
like image 85
Tholle Avatar answered May 25 '26 09:05

Tholle