I’m currently using the following script but encountering an error that states:
unexpected error in UrlFetchApp.fetch()
function createArchive() {
var oauthSettings = UrlFetchApp.addOAuthService("docsAPI");
oauthSettings.setAccessTokenUrl("https://www.example.com/oauth/access");
oauthSettings.setRequestTokenUrl("https://www.example.com/oauth/request?scope=https://docs.example.com/api/");
oauthSettings.setAuthorizationUrl("https://www.example.com/oauth/authorize");
oauthSettings.setConsumerKey(consumerKey);
oauthSettings.setConsumerSecret(consumerSecret);
var requestOptions = {
"method": "POST",
"headers": { "GData-Version": "3.0" },
"oAuthServiceName": "docsAPI",
"payload": generatePayload(),
"oAuthUseToken": "always"
};
var apiEndpoint = 'https://docs.example.com/api/archive';
var response = UrlFetchApp.fetch(apiEndpoint, requestOptions);
}
function generatePayload() {
var xmlString = '<?xml version="1.0" encoding="UTF-8"?>' +
'<atom:entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.example.com/docs/2007">' +
'<docs:archiveConversion source="application/vnd.google-apps.document" target="application/msword"/>' +
'<docs:archiveConversion source="application/vnd.google-apps.spreadsheet" target="text/csv"/>' +
'<docs:archiveConversion source="application/pdf" target="application/pdf"/>' +
'</atom:entry>';
Logger.log(xmlString);
return xmlString;
}
If there’s an alternative method to achieve this, please share it with me as soon as possible. Thank you!