Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending existing draft with node.js Gmail API

I'm attempting to use the users.drafts.send API to send a Gmail draft which already exists. Despite a lot of searching I haven't been able to find a lot of concrete information about what the request should actually look like. The requests I've tried are:

gmail.users.drafts.send( { 'userId': user, 'resource': { 'id': msg_id } }, callback );

This results in a 'Not Found' error.

Based on some searching which seemed to imply that the draft resource needs to be in a sub-object called draft, I tried:

gmail.users.drafts.send( { 'userId': user, 'resource': { 'draft': { 'id': msg_id } } }, callback );

That results in an "Invalid Draft" error. Which I suppose is a better error, but I still can't get it to actually send.

I've confirmed that the message ID and user ID strings are the correct ones, and there aren't any auth issues. (Other API calls are working fine.)

like image 333
friedo Avatar asked Jun 16 '26 22:06

friedo


1 Answers

Your first example is correct, but I think you are missing something.

I have a draft. I will list it with the API Explorer:

Request

GET https://www.googleapis.com/gmail/v1/users/me/drafts?access_token={ACCESS_TOKEN}

Response

{
 "drafts": [
  {
   "id": "1527269226973690353",
   "message": {
    "id": "1531f3452626f9f1",
    "threadId": "1531f3452626f9f1"
   }
  }
 ],
 "resultSizeEstimate": 1
}

As you can see, the draft has two ids. One regular messageId which will not work when doing draft specific operations, and the id which is the draftId you should be using.

like image 57
Tholle Avatar answered Jun 19 '26 10:06

Tholle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!