Skip to Content
Technical Articles
Author's profile photo ASUTOSH MAHARANA

SharePoint Integration using SAP CPI (Without SAP Open Connector)


Sometimes documents need to be copied to the SharePoint team site so that it can be made accessible to broader recipients within an organization.


This integration requires configuration changes in SharePoint as well as SAP CPI.

SharePoint App Configuration

Register Add-In

On the initial stage, we have to register the Add-In in SharePoint, where we want to access the information. Follow the steps below to register the Add-In in SharePoint site.

  • Navigate and login to SharePoint online site.
  • Then navigate to the Register Add-In page by entering the url as
  • https://<siteURL>/_layouts/15/appregnew.aspx
  • On the App Information section, click the Generate button next to the Client Id and Client Secret textboxes to generate the respective values.
  • Enter Add-In Title in Title textbox
  • Enter AppDomian as a localhost
  • Enter RedirectUri as a https://localhost
  • Click Create button, which registers the add-in and returns the success message with created information.


Register SharePoint Add-ins


Grant Permissions to Add-In

Once the Add-In is registered, we have to set the permissions for that add-in to access the SharePoint data. We will set the Read permission level to the web scope, so that we will be able to read the web information.

  • Navigate to the SharePoint site
  • Then enter the URL https://<siteURL>/_layouts/15/appinv.aspx in the browser. This will redirect to the Grant permission page.
  • Enter the Client ID(which we have generated earlier), in the AppId textbox and click the Lookup button. That will populate the value to other textboxes in Title, App Domain and Redirect Url.


Grant Permissions to Add-In

  • Now enter the below permission request in XML format.
<AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Write" />
  • Then click the Create button. This will redirect to your page, where we have to trust the add-in to read items from the website.

Note: If we want to access site collection or tenant level, we have add the xml accordingly.


Retrieve the Tenant ID

Once we register the Client Id and Secret with the permissions, we are ready to access the SharePoint information from external systems or tools.

First, we have to know the Tenant ID. Follow the below steps to obtain that information from the postman. Postman helps to get the tenant Id by requesting the below url with Authorization header.

  • Launch Postman.
  • Select Get Method
  • Enter the below URL in the “Request URL” textbox
  • https://<siteURL>/_vti_bin/client.svc/
  • Configure the below information in the header section to send along with the url requestMethod = Get


Get Call for Tenant ID

  • After applying the configuration, click the Send button. The response returns a lot of headers but ends with unauthorized access.


Response Headers

In response header, we will get WWW-Authenticate as one of the headers and that contains the necessary information required for the next step. The realm value contains the tenant id for the SharePoint Online site and clientid value contains the resource information (we’ll use it later in our SAP CPI iFlow).


SAP CPI iFlow Configuration



This iFlow is creating one webservice which can be triggered by any HTTP Client and upload files to SharePoint using REST api V1 of SharePoint.

Here we have used parallel multicast to get the OAuth access token from Microsoft Access Control Services.


OAuth Call Branch

OAuth Request

First of all we are using a content modifier step to create the request. 

  • Request Header: We have added one header with key and value pair as “Content-Type” and “application/x-www-form-urlencoded”.
  • Request Body: We have to add the below string to the message body section with appropriate replacement.
  • ClientID: Created in the Add In section
  • ClientSecret: Created in the Add In section
  • TenantID: Fetch from “WWW-Authenticate” header in the last section
  • resource: Fetch from “WWW-Authenticate” header in the last section
  • SiteDomain: Domain name


Call to MACS and HTTP Receiver

Then we have a request reply step which will call the Microsoft Access Control Services and fetch the response. HTTP receiver channel should be updated with the below address and “POST” Method.



JSON to XML Converter and Fetch Access Token

As we are getting one JSON response we need to convert it to XML format and then we have used another content modifier to fetch the access token and assign it to a property called “access_token”.





Remove Body

We have used one simple Groovy script to remove the body of the OAuth call branch.

import groovy.json.JsonOutput

Message processData(Message message) {
    def body = "";
    return message;


Final Call to SharePoint


Join and Gather

We have used Join and Gather to merge both the branches. So that we can get an OAuth access token as well as the original message body from the request.


Set Header

We have used one content modifier to create 2 headers with a key value pair as below. We have also deleted the unused headers.

Key :: Value

Content-Type :: application/xml (You can change the value as per your requirement)

Authorization :: Bearer ${property.access_token}





We have also created one exchange property to transmit the filename.




Convert Body to outputStream

As per our understanding the request body should be passed to the HTTP adapter but as per our testing the content modifier or ${body} is not giving required results when the request body is passed directly (SharePoint REST API is giving 500 error with I/O error). So we have used one simple groovy script to convert the payload to ByteArrayOutputStream and again set it to the message body. (Not sure why it is behaving like this as we are still investigating this issue.)

import java.util.HashMap;
def Message processData(Message message) {
       def body = message.getBody(String.class);
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
       return message;


Call to SharePoint

We are making a POST call to SharePoint REST api using request reply and HTTP receiver channel.


HTTP Receiver



We have called the HTTP endpoint of the iFlow from a Postman client.


Call from Postman



We can see the files being sent to the SharePoint.





With this you have successfully created and tested an integration flow that is uploading documents  to SharePoint, created a team site in SharePoint, leveraged the SAP CPI to connect seamlessly to SharePoint site. Basically we need to take care of the HTTP request payload while calling the rest api of SharePoint. Please go through the Microsoft documentation for API overview.



Assigned tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Daniel Graversen
      Daniel Graversen

      Nice post.

      I would often save the payload in the Exchange properties and then restore it afterwards.

      Author's profile photo Yeswanth Posam
      Yeswanth Posam

      Hi Asutosh,

      Did u check uploading binary (ppt,pdf,word..) files.

      I am unable to post binary data to Sharepoint eventhough my headers and request payload is correct

      Input Attachment


      Input attachment

      Groovy script code to read attachments and set header data(tried with ByteArrayOutputStream also)

      Map<String, DataHandler> attachments = message.getAttachments()

      List<String> aList = new ArrayList<String>();

      for (String x : attachments.keySet())




      def attch=attachments.get(aList.get(0))


      def xcn=attch.getInputStream().getBytes()



      def ctype=attch.getContentType().indexOf(';')


      return message


      Message Content from trace step

      Message Header


      Message Headers

      Body(Binary data)

      Binary data which is downloaded and saved with the extension is of actual file


      Msg before Step

      Error in SAP CPI


      Error in CPI

      Exception from sharepoint 

      <?xml version="1.0" encoding="utf-8"?>
      <m:error xmlns:m="">
      <m:code>-1, System.IO.IOException</m:code>
      <m:message xml:lang="en-US">I/O error occurred.</m:message>

      Could you please help me with this.

      Author's profile photo ASUTOSH MAHARANA
      Blog Post Author

      Dear Yeswanth,


      I have also tried to modify the script to assign binary payload to the request body but it's giving same I/O error. It seems like conversion to string only working fine as of now.


      I have observed that HTTP adapter is converting the type of request body to "inputStream" but it seems like there is some issue with the SAP CPI HTTP receiver adapter which is not able to pass byte streams correctly. I have tried using Postman it is working fine.


      I am trying to create a custom HTTP adapter from Apache components and try to use that adapter to connect to SharePoint.



      Asutosh Maharana

      Author's profile photo Faisal Jamal
      Faisal Jamal

      Were you able to resolve this issue? I am also facing Error 500 I/O exception while trying to send the binary data to Sharepoint. The payload looks fine and I am able to open it up as a pdf when downloaded.


      Author's profile photo Yeswanth Posam
      Yeswanth Posam

      Hi Asutosh,

      I also feel it is issue with HTTP Adapter based on below screenshots. I think issue is also with encoding, as per HTTP adapter default encoding is UTF-8.

      Input Attachment


      Message Before Step in Adapter



      Downloaded and opened above binary data in Notepad++(length is as expected and encoding in ANSI) and saved it with .pptx as is working as expected.


      Message before Receiver Adapter(here is the step where the file encoding is getting changed)

      Downloaded and opened above binary data in Notepad++(length is not as expected and encoding in UTF-8 as per HTTP adapter standards)

      Encoding change as per below SAP Documentation

      Encoding property as per above SAP blog (changed CamelCharsetName to overwrite standard UTF-8 encoding)

      File in Notepad++ after above encoding change (almost original input attachment data expect few characters unable to find the exact encoding for ANSI as ANSI is not an encoding type)



      Author's profile photo ASUTOSH MAHARANA
      Blog Post Author

      Dear Yeswanth,


      I have a workaround for this issue not sure if it will help you or not.

      We can first convert the binary payload to base64 encoded string then transfer it to SharePoint and create one text file. Then we can use Power Automate flow to convert the base64 encoded text file to binary file again.

      Power Automate flow: It's a manually triggered flow but you can create an automated flow as well. Let me know if you are facing any issue with power automate.


      Base64 to binary

      Will this suffice your requirement ?

      I am also looking into the charset conversion issue of the HTTP receiver adapter.



      Asutosh Maharana

      Author's profile photo Erkam Ozturk
      Erkam Ozturk

      Hi Yeswanth, Asutosh,

      Were you able to find a solution for the binary files? I'm also suffering from this problem.




      Author's profile photo Erkam Ozturk
      Erkam Ozturk

      Hi all,

      For the upload of binary files to a SharePoint site, I've just come up with such a solution; Instead of CPI's own HTTP receiver adapter, I'm uploading the files via HTTP call from the groovy.  That works fine. Here is my code:

      import java.util.HashMap;
      def Message processData(Message message) {
          String contentLength = message.getBodySize();
          def Content = message.getBody(byte[])
          def messageLog = messageLogFactory.getMessageLog(message);
          def propertiesMap = message.getProperties();
          def headersMap = message.getHeaders();
          def siteDomain = propertiesMap.get("siteDomain");
          def site = propertiesMap.get("site");
          def pathSpaceCorrected = propertiesMap.get("pathSpaceCorrected");
          def fileName = propertiesMap.get("fileName");
          String SharePointURL = 'https://' + siteDomain + '/sites/' + site + '/_api/web/GetFolderByServerRelativeUrl(\'' + '/sites/' + site  + pathSpaceCorrected + '\')/Files/add(url=\'' + fileName + '\',overwrite=true)';
          // POST
          def post = new URL(SharePointURL).openConnection();
          post.setRequestProperty("Content-Type", headersMap.get("Content-Type") as String);
          post.setRequestProperty("Content-Length", contentLength ); 
          post.setRequestProperty("Authorization", headersMap.get("Authorization") as String);
          def postRC = post.getResponseCode();
          if(postRC.equals(200)) {
              message.setBody("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><status>Uploaded</status></root>");       
              messageLog.addAttachmentAsString("Post result:", post.getInputStream().getText() as String, "text/plain")
              message.setBody("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><status>Failed</status></root>");
              def exceptionMsg = "HTTP" + postRC.toString() + ", " + post.getInputStream().getText()
              throw new Exception(exceptionMsg as String)
          return message

      Reference articles:

      Nick Yang's solution, and Joao Miguel Gomes's contribution:

      Rajath Kodandaramu's article:



      Erkam Ozturk

      Author's profile photo ASUTOSH MAHARANA
      Blog Post Author

      Dear Erkam,


      I think it's not recommended to do HTTP call directly from scripts without using any adapter from SAP CPI or any integration platform as it will cause issues for tracing and logging. We discourage developers to call the webservices from Java mapping as well in SAP PO for this reason.

      And there is no point in having all the processing steps or adapters in SAP CPI as well because we can do all the operations using Groovy scripts basically.

      The real culprit is SAP CPI's HTTP receiver adapter where we are getting the error due to charset conversion. Because we are already aware of this solution to call the APIs directly from script.


      You can go through the Power Automate flow alternative as well.


      Asutosh Maharana

      Author's profile photo Yeswanth Posam
      Yeswanth Posam

      Hi Erkam,

      Even I could post files directly to Sharepoint using script but it is not recommended to follow that approach, so trying to use receiver adapter for posting files.




      Author's profile photo Faisal Jamal
      Faisal Jamal

      Hi All,

      I am also facing the same issue while sending the binary data to SharePoint through HTTP receiver adapter in SAP CPI.

      Is there any other solution to this without using the Groovy script to directly call SharePoint or Power Automate flow?

      Thanks in advance!



      Author's profile photo Shameer Shaik
      Shameer Shaik

      Hello Ashutosh, Were you able to resolve issue of sending pdf's or pptx via http receiver adapter. If please provide insights .

      Author's profile photo ASUTOSH MAHARANA
      Blog Post Author

      Dear Shameer,

      It seems like a standard behaviour of HTTP adapter to put UTF-8 encoding. But when we change the encoding of binary files, it seems like it corrupts the file and also changes the file length. This is the reason of failure.



      Author's profile photo Shameer Shaik
      Shameer Shaik

      Any alternative way overcome that. In my case I have to send binary data(pdf/gif) to Azure blob storage using HTTP adapter.



      Author's profile photo Shameer Shaik
      Shameer Shaik

      Any alternative way overcome that. In my case I have to send binary data(pdf/gif) to Azure blob storage using HTTP adapter.



      Author's profile photo ASUTOSH MAHARANA
      Blog Post Author

      Only alternative I can think of is to send it via simple groovy script to call instead f http adapter.(or open connectors if you have license). But you should also explore more in http adapter.

      Author's profile photo Shameer Shaik
      Shameer Shaik

      Since we have standard connector provided by SAP, Performing http calls via script is not a good practice and debugging also will cause some problem.

      I have tried using SAP PO rest adapter , It's working fine there.

      Let me also raise it to SAP .Thanks Asutosh for providing more insights.

      Author's profile photo sivasankar chagaleru
      sivasankar chagaleru

      Hi maharana what you explained was very nice

      I am struk in creating content modifier could you please upload images of each and every step it would be easy to unserstand for us thank you hope you can upload pictures.

      Author's profile photo Mahesh Sabba
      Mahesh Sabba

      Hi Asutosh,


      Very useful blog, Thank you.


      I am doing the same integration now to upload the .csv files from CPI sharepoint path, i have followed the same steps as per the blog and Bearer token also generated.

      But while passing the same token in the header to connect to sharepoint getting the 401 authorization error with the below error description

      {"error_description":"Invalid JWT token. Could not resolve issuer token."}

      Could you please help me with this error ,Whether am i missing something to pass while connecting to sharepoint.


      Thanks & Regards,