Search code examples
web-servicesgoogle-apps-scriptsoapbindingsaprfc

How to call web service on google app script


I created a web service in SAP and I tried to call this SOAP web service from google app script.

This WS is in BASIC authentication, in variable response I receive the same wsdl that I pass in input.

I encountered a problem in back-end system call

Unsupported Content Type is received: " "

Someone can help me?

var user = 'user';
var pwd = 'pwd';
var webservice = 'http://xx.xxx.xx.xx:xxxx/sap/bc/srt/wsdl/flv_10002A111AD1/bndg_url/sap/bc/srt/rfc/sap/zdemo_google_ws/100/zdemo_google_ws/zdemo_google_ws?sap-client=100.wsdl';
function readData() {  

//Clean up anything currently on the spreadsheet  
SpreadsheetApp.getActiveSheet().clear();  

try {  

//Various XML parsing.  
var xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:soap:functions:mc-style\">"
+"<soapenv:Header/>"
+"   <soapenv:Body>"
+"     <urn:ZDemoGoogle>"
+"         <ItWebs>"
+"            <item>"
+"               <Protocol></Protocol>"
+"               <Tasktype></Tasktype>"
+"               <EntryId></EntryId>"
+"               <Account></Account>"
+"               <Mandt></Mandt>"
+"               <Host></Host>"
+"               <Port></Port>"
+"               <Destination></Destination>"
+"               <Path></Path>"
+"               <Counter></Counter>"
+"               <Calltime></Calltime>"
+"               <ExecutionTi></ExecutionTi>"
+"               <DataSend></DataSend>"
+"               <DataSendTi></DataSendTi>"
+"               <DataReceive></DataReceive>"
+"               <DataReceiveTi></DataReceiveTi>"
+"            </item>"
+"         </ItWebs>"
+"      </urn:ZDemoGoogle>"
+"   </soapenv:Body>"
+"</soapenv:Envelope>"

var options = {  
  headers: {  
    "Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd),
    "method" : "post",
    "contentType" : "text/xml",
    "payload" : xml,
    "muteHttpExceptions":true
  },  
};  

//UrlFetchApp is a powerful built-in library from Google  

var serviceaddress =  webservice ;
var response = UrlFetchApp.fetch(serviceaddress, options);

Solution

  • In order to use UrlFetchApp.fetch(), it is required to modify option of your script. So how about this modification?

    From :

    var options = {  
      headers: {  
        "Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd),
        "method" : "post",
        "contentType" : "text/xml",
        "payload" : xml,
        "muteHttpExceptions":true
      },  
    };
    

    To :

    var options = {  
      headers: {"Authorization": "Basic " + Utilities.base64Encode(user + ':' + pwd)},
      method: "post",
      contentType: "text/xml",
      payload: xml,
      muteHttpExceptions: true,
    };
    

    Reference :

    If this was not the direct solution of your issue, I'm sorry.