I have created a draft message using "media upload" method using below code
var draftUploadUrl = "https://www.googleapis.com/upload/gmail/v1/users/me/drafts?uploadType=media";
var response = UrlFetchApp.fetch(draftUploadUrl, {
method: "POST",
headers: {
//authorizing request through service account
"Authorization": "Bearer " + service.getAccessToken(),
"Content-Type": "message/rfc822",
},
muteHttpExceptions: true,
//payload_data is mime content with base64 encode of email body an
//attachment
payload: payload_data
});
draftID = /: "(.*)"/.exec(response.getContentText())[1];
console.log("draftID: " + draftID);
I get a draft ID of the message, how can I set draft ID in parameters to send the email with an attachment?
code snippets
var resp1 = UrlFetchApp.fetch("https://www.googleapis.com/upload/gmail/v1/users/me/drafts/send?uploadType=media", {
method: "POST",
headers: {
"Authorization": "Bearer " + service.getAccessToken(),
"Content-Type": "message/rfc822"
},
muteHttpExceptions: true,
payload: JSON.stringify({
"id": draftID
})
});
it is throwing error "Invalid draft".Can you please guide how to pass ID parameter for above url call or what went wrong in above code?
Thanks in advance.