0

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.

Talha Masood
  • 993
  • 1
  • 7
  • 22
  • Did you check this link http://stackoverflow.com/questions/25494664/creating-a-gmail-draft-with-recipients-through-gmail-api/25494682#25494682 – SGC Mar 05 '15 at 18:10

1 Answers1

0

I just encountered this issue, it looks like the API client changed the way it expects the payload. I had to remove the draft attribute to fix this :

      var request = gapi.client.gmail.users.drafts.create({
        userId: "me",
        message: {
            raw: ...)
          }
      }
David
  • 5,481
  • 2
  • 20
  • 33