I am trying to write a GAS
to migrate some emails which are stored in Google Drive
but I am really struggling to get the POST correct to do this and was hoping someone could help me out and steer me in the right direction.
What I have so far is ..
var id = "12345678abcdefgh";
var doc = DocumentApp.openById(id);
var emlData = doc.getText();
var api_scope = 'https://www.googleapis.com/auth/email.migration';
var app_name = "migration";
var userKey = "someone@mygappsdomain.com";
var method = "POST";
var url = "https://www.googleapis.com/upload/email/v2/users/"+userKey+"/mail?uploadType=multipart";
var fields = {"MailItem" :
{"properties":
{'isInbox': 'true','isUnread': 'true'},
'labels': ['MigrateMe']}};
var options = {payload: {data: JSON.stringify(emlData), fields: fields, contentType: 'multipart/related', boundary : 'part_boundary'}};
var fetchArgs = googleOauth_(app_name,api_scope,method,options);
try
{
var result = UrlFetchApp.fetch(url, fetchArgs).getResponseCode();
Logger.log("done");
}
catch (ee)
{
Logger.log(ee);
}
}
This obviously doesn't work and I get a 400 error code. Do you know what could be wrong ?