Reputation: 168
I am trying to use the Gmail REST APIs to mark a message as read.
$('#markGmailRead').click(function(){
var request = $.ajax({
type: 'POST',
dataType: 'json',
headers: { "Authorization": "Bearer <<ACCESS KEY>>",
"Content-Type": "application/json"},
url: 'https://www.googleapis.com/gmail/v1/users/me/messages/<<MESSAGEID>>/modify',
data: {"addLabelIds": ["UNREAD"]}
})
request.done(function(data){
// when the Deferred is resolved.
console.log(data);
})
request.fail(function(){
// when the Deferred is rejected.
console.log('fail');
})
})
This results in the following json returned:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Has anyone else experienced this? I'm at a loss as to what may be causing this.
Upvotes: 3
Views: 3086
Reputation: 8445
I had the same problem doing this in Meteor. The problem was I was passing the removeLableIds in the 'params' attribute. Changing to the 'data' attribute worked, i.e.
var apiUrl = "https://www.googleapis.com/gmail/v1/users/me/messages/"
+ messageID + "/modify";
var result = HTTP.post( apiUrl, {
data: { "removeLabelIds": ["INBOX"] },
headers:{
"content-type":"application/json ; charset=UTF-8",
"Authorization": "Bearer " + tokens.accessToken
}
});
Upvotes: 1
Reputation: 168
I was able to figure this out and get it working. The only difference to be made was to stringify the data like so:
data: JSON.stringify({"removeLabelIds":["UNREAD"]}),
Making this change made it work.
Upvotes: 2