This question has been asked a few times but none of the answers has solved my problem.
I am trying to save a draft using Gmail API in JavaScript. But I get the following error.
"message": "Missing draft message"
I know the reason is that I am unable to encode my arguments properly in RCF 2822 format although I have taken all the necessary measures. Following is my code:
gapi.client.load('gmail', 'v1', function() {
var request = gapi.client.gmail.users.drafts.create({
'userId': "me",
'draft': {
'message': {
'raw': btoa("From: me\r\nTo:" + "hello@person.com" + "\r\nSubject:"+ "subject" + "\r\n\r\n" + "message")
}
}
});
request.execute(function(data){
console.log(data)
});
});
I have properly converted the draft email using btoa Can't see what I am missing.
Some of the answers on SC are related to Ruby. Almost none of the solutions work in my scenario. I have tried passing simple string as draft message still get the same issue.
Please guide me where I am wrong.
P.S I am successfully able to send email via Gmail API using almost the same code and encoding. But I can't save messages as drafts.