Skip to Content

Read SharePoint items using SAP PI UDF


Here, we will see, that, how we can read SharePoint’s AlertCount list item using SAP-PI UDF.

To read ShaePoint AlertCount list item, following SharePoint-REST protocols can be used:

    • https://<org_Shp_Host>/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle(‘AlertCount’)/GetItemById(‘<ID>’)
  • Method:
    • GET
  • Headers:
    • Authorization  : “Bearer ” + <SharePointAccessToken>
  • where,
    • <org_Shp_Host> is Organisation’s SharePoint host name
    • <ID> is unique item Id of every record inside AlertCount List
    • <SharePointAccessToken>: it is security token required to authenticate SharePoint REST request while inserting items, this token can be fetched from following blog’s udf:

SAP PI Java UDF example to read AlertCount list items of SharePoint

  • Suppose, if we want to read Item ‘E01’ from sharePoint as shown in below SharePoint-screen
  • , then using its ID (itemID) inside SharePoint-REST as below:
    • https://<org_Shp_Host>/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle(‘AlertCount’)/GetItemById(‘21115’)
  • , we can fetch complete detail using following UDF example:
public String readAlertCount(String accessToken, Container container) throws StreamTransformationException{
		String response = "";
		try {
			// SharePoint url to fetch AlertCount List
			String wsURL = "https://<org_Shp_Host>/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle('AlertCount')/GetItemById('21115')";

			// Create HttpConnection
			URL url = new URL(wsURL);
			URLConnection connection = url.openConnection();
			HttpURLConnection httpConn = (HttpURLConnection) connection;

			// Set Header
			httpConn.setRequestProperty("Authorization", "Bearer " + accessToken);

			// Read the response.
			InputStreamReader isr = null;
			if (httpConn.getResponseCode() == 200) {
				isr = new InputStreamReader(httpConn.getInputStream());
			} else {
				isr = new InputStreamReader(httpConn.getErrorStream());
			BufferedReader in = new BufferedReader(isr);
			String responseString = "";

			// Write response to a String.
			while ((responseString = in.readLine()) != null) {
				response = response + responseString;
		} catch (Exception e) {
			response = "Error: " + e.getMessage();
		return response;
  • Result of UDF will be a xml string like below:



<<<<< Parent blog reference…..  Integrate SharePoint using SAP PI

Be the first to leave a comment
You must be Logged on to comment or reply to a post.