unable to create a label in gmail api using javascript

511 Views Asked by At

Sorry for being Amateur at this but please help,I am trying to create new label name news1 and this is code i have done.

This is the function call which i have used.

createLabel();

My function

 function createLabel() {
var newLabelName="news1";
 var request = gapi.client.gmail.users.labels.create({

'userId' : 'me',
'labels' : {
"labelListVisibility"   : "labelShow",
"messageListVisibility" : "show",
"name" : newLabelName,
"id" : "news"
}
});
request.execute();
}
2

There are 2 best solutions below

0
On

If you use your function like this only, it can't works. You have to authenticate yourself first with a client id provided by Google and permissions scopes you need for your code.

Ressources :

Quickstart with gmail js (authentification) : https://developers.google.com/gmail/api/quickstart/js Creation label doc : https://developers.google.com/gmail/api/v1/reference/users/labels/create

0
On

You cannot specify the Label ID. It will be provided to you in the response if the Label is successfully created.