Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 

This is a submission for the SAP Intelligent RPA Tutorial Challenge.

This blog post offers an overview of how a SOAP API can be used in SAP S/4HANA process bot using SAP Intelligent Robotic Process Automation . The template bots are delivered in SAP Best Practices Explorer “SAP Best Practices for SAP Intelligent Robotic Process Automation Integration with SAP S/4HANA“. For downloading the source code refer the release note 2788986 - Release Strategy for SAP Best Practices for SAP Intelligent Robotic Process Automation for SAP S/4HANA.

Below are the template bots having SOAP API call:

Following steps need to be followed for handling the SOAP API using SAP Intelligent RPA tool:

  1. Setup the project in Desktop Studio

  2. Ensure that proper Communication Scenario setup is done for the API in the system and you have the WSDL of the SOAP API

  3. For generating the SOAP Envelope (payload) either import the WSDL file in the SoapUI application by Smart bear which automatically interprets the WSDL file and forms the soap envelope or write down the soap envelope in xml format in the below format:
    <?xml version="1.0"?>






    A sample SOAP Envelope with values in SoapUI application looks like:

  4. Fill in appropriate values in the xml soap envelope which you want to pass to the API as payload for the various properties in the API as a key value pair

  5. The API request type must be POST and the body/payload must be in XML with the ‘Content-Type’ request header as ‘text/xml’

  6. Refer the below code snippets for handling SOAP API calls

    • The POST request can be done by either using xhr or ajax, over here we are taking xhr into consideration:
      //function to construct the XHR object 
      function getXhr() {
      var xhr = null;
      try {
      try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
      ctx.log("getXhr new ActiveXObject('Msxml2.XMLHTTP')");
      } catch (e) {
      try {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
      ctx.log("getXhr new ActiveXObject('Microsoft.XMLHTTP')");
      } catch (e) {
      xhr = new window.XMLHttpRequest();
      ctx.log("getXhr new window.XMLHttpRequest()");
      return xhr;
      } catch (e) {
      ctx.log(" *** getXMLHTTPRequest *** " + e.description);
      return null;

    • Construct the headers, body/payload, etc. and POST the request using the below code snippet:
      //a custom method for handling SOAP API call
      function soapApiCall() {
      var xhr = getXhr();
      /** form a custom object
      *with the mandatory information
      *required for the API call,
      *like URL, payload, etc.
      var request = {
      apiUrl: apiEndPoint,
      /**payloadProject value
      *contains XML format payload
      *of the SOAP Envelope
      apiPayload: payloadProject,
      communicationUser :communicationUser,
      communicationPassword : communicationPassword
      try {
      postCall(xhr, request);
      catch (e) {
      ctx.log("SOAP API Call Failed");
      return ;
      var status = xhr.status;
      ctx.log("Status " + status);
      var statusText = xhr.statusText;
      ctx.log("Status Text : " + statusText);
      ctx.log("xhr: " + xhr);
      var responseText = xhr.responseText;
      ctx.log("response: " + responseText);
      var rawResponse = xhr.responseXML;
      ctx.log("raw xml : " + rawResponse);
      rootData.soapResponse = rawResponse;
      var soapJsonResponse = ctx.xml.xml2json(rootData.soapResponse, "");
      var jsonResponse = ctx.json.stringify(soapJsonResponse, null, 4);

    • Code snippet for hitting the API using the headers and body/payload:
      //function which handles the POST call request
      function postCall(xhr, request) {"POST", request.apiUrl, false);
      //Set All the Required Headers
      xhr.setRequestHeader('Content-Type', 'text/xml');
      if (request.communicationUser != '' && request.communicationPassword != '') {
      xhr.setRequestHeader("Authorization", "Basic " + ctx.base64.encode(request.communicationUser + ':' + request.communicationPassword));
      xhr.setRequestHeader("Accept", "*/*");

Sometimes the API response logs are maintained in AIF (Application Interface Framework), hence the user will have to check the AIF logs for the API response.

Following the above steps and code snippets we are able to use SOAP API in SAP S/4HANA process bot.

Try this out, let me know in the comments if you face any challenges.

Stay tuned for more technical blog post related to SAP S/4HANA process automation content!

For more information on SAP S/4HANA, check out the following links:

  • Best practices for SAP S/4HANA Cloud here

  • SAP S/4HANA Cloud User Community: register here

  • Sven Denecken’s blog post on Intelligent ERP Update: SAP S/4HANA Cloud 1911 Release here

  • Sven Denecken’s blog post on Intelligent ERP Update: SAP S/4HANA Cloud 1908 Release here

  • Sven Denecken’s blog post on SAP News here

  • Intelligent ERP Update: SAP Intelligent Robotic Process Automation Content in SAP S/4HANA Cloud 1911 – (Deep Dive) here

1 Comment