Spend Management Blogs by SAP
Stay current on SAP Ariba for direct and indirect spend, SAP Fieldglass for workforce management, and SAP Concur for travel and expense with blog posts by SAP.
cancel
Showing results for 
Search instead for 
Did you mean: 
ajmaradiaga
Developer Advocate
Developer Advocate









In this blog post I cover how we can configure an integration flow in SAP Cloud Integration to communicate with the SAP Ariba Operational Reporting APIs. To achieve this, I will use the trial version of the Integration Suite available in SAP BTP. We will build an integration flow in SAP Cloud Integration, process the request response using a Groovy script and store the request response in the data store.


To complete the steps explained in this blog post, there are some prerequisites that we will need to complete first:

  • Create application in SAP Ariba Developer Portal and request API access to the Analytical reporting APIs. Unfortunately there is no trial version of SAP Ariba but I guess that if you are reading this blog post, it is because your company uses SAP Ariba :-). I covered in a previous blog post (Using the SAP Ariba APIs to extract inactive suppliers) how to create an application and request API access in the SAP Ariba Developer Portal.
    If you prefer watching videos, you can watch the first two videos available in the SAP Ariba for Developers YouTube playlist ? https://www.youtube.com/playlist?list=PL6RpkC85SLQDXSLHrSPtu8wztzDs8kYPX.


  • An SAP BTP trial account. Make sure to enable to a subscription to the Integration Suite (Go to your trial subaccount > Subscriptions > Integration Suite). Once in the Integration Suite application, add the
    Design, Develop and Operate Integration Scenarios (SAP Cloud Integration) and Extend Non-SAP Connectivity (Open Connectors) capabilities.
    To find out how to create a trial account: https://developers.sap.com/tutorials/hcp-create-trial-account.html



Now that we have access to the different systems, I will proceed to explain how to get SAP Cloud  Integration talking with SAP Ariba. I will build an integration flow in SAP Cloud Integration whose goal is to extract operational data from SAP Ariba and store the response as an entry in a data store. To accomplish this we will do the following:

  1. Deploy the SAP Ariba application details as security material in SAP Cloud Integration

  2. Create and set up integration flow in SAP Cloud Integration


The integration flow end result is shown below.


Integration flow



The full Groovy script and an export of the above integration flow can be found in the SAP Ariba Extensibility Samples repository > topics > integration > cloud-integration-connection - https://github.com/SAP-samples/ariba-extensibility-samples/tree/main/topics/integrations/cloud-integ...

Step 1 – Deploy the SAP Ariba application details as security material in SAP Cloud Integration


Go to your SAP Cloud Integration instance and create/deploy a security material (Monitor > Manage Security > Security Material). This will be used by the integration flow to communicate with SAP Ariba.















Name Type Fields
Ariba Operational Reporting API OAuth2 Client credentials Enter the Token service URL, Client ID and Client Secret. This details will be provided to you when generating the OAuth credentials in the Developer Portal.




SAP Ariba application details



Step 2 - Create and set up integration flow in SAP Cloud Integration


Create an integration flow in SAP Cloud Integration following the guidelines below.

Given that it is possible to receive large amounts of data from the SAP Ariba Operational Reporting APIs, there might be a need to paginate the response. This is taken in consideration in the integration flow, hence why there is a looping process in it.
To understand how pagination works in the SAP Ariba APIs, check out the explanation in Exercise 08 of the Cloud APIs virtual event - Data pagination with SAP Ariba APIs.

I created the externalized parameters below to ensure that the integration flow is reusable.


Externalised parameters



Integration Process


The integration flow includes an integration process that can start on a schedule and a looping process call to handle the SAP Ariba response pagination. The loop will stop when the header pageToken value is STOP. This is handled by the script responsible of processing the SAP Ariba API response.


Retrieve Operational Reporting data from SAP Ariba (Local integration process)


This local integration process retrieves the operational data from SAP Ariba and stores it in a Data store entry. Below, the details  and screenshots on what each block in the process is doing:

  • Ariba Setup: Sets the externalised parameters as header values for the integration flow to use them when calling SAP Ariba.



Ariba Setup - Message headers




  • Set Ariba dateFilter parameter (Groovy script): Specify the date filter expected when calling the view template. The dateFilter included in the script will set a date based on the externalised parameters specified.


def Message setAribaDateFilter(Message message) {
def messageLog = messageLogFactory.getMessageLog(message)

//Get Headers
def map = message.getHeaders();
def updatedDateFrom = map.get("updatedDateFrom")
def updatedDateTo = map.get("updatedDateTo")

def dateFrom = "updatedDateFrom"
def dateTo = "updatedDateTo"

// Set the value for filters query parameter
if(updatedDateFrom != "" && updatedDateTo != "") {
message.setHeader("dateFilter", '{"' + dateFrom + '":"'+ updatedDateFrom + '","' + dateTo + '":"'+ updatedDateTo + '"}')
} else {
def dates = calculateDates(map.get("dateInterval", 60) as int)

def dateFilter = '{"' + dateFrom + '":"' + convertDateToAribaStringFormat(dates[0]) + '","' + dateTo + '":"' + convertDateToAribaStringFormat(dates[1]) + '"}'

message.setHeader("dateFilter", dateFilter)
messageLog.setStringProperty("dateFilter", dateFilter)
}

return message
}


  • GET Operational Reporting data (HTTP to SAP Ariba):



SAP Ariba HTTP connection




  • Process SAP Ariba response (Groovy script): This script checks for the PageToken value in the API response and handles its value. This will be used to indicate if the looping process should continue or finish. It also sets the value of the data store entry.


def Message processAribaResponse(Message message) {

def messageLog = messageLogFactory.getMessageLog(message)

//Body
def body = message.getBody(String);

// Convert payload to JSON object
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(body)

if(!("Records" in object) || object.Records == []) {
// No elements to process
message.setHeader("pageToken", "STOP");
message.setProperty("entryId", "Response");

} else {

// Retrieving PageToken from payload if one exists
if("PageToken" in object) {
messageLog.setStringProperty("PageToken", object.PageToken);
message.setHeader("pageToken", object.PageToken);
message.setProperty("entryId", "Response_" + object.PageToken);
} else {
messageLog.setStringProperty("PageToken", "NONE!");
message.setHeader("pageToken", "STOP");
message.setProperty("entryId", "Response");
}
}

return message;
}


  • Write API response: The response from the SAP Ariba API will be stored in the data store. The name of the data store will be AribaOperationalReporting and the entry will be Response and/or Response_{PageToken} if there is pagination.



Write Data Store - Processing


Now that all steps are completed, we deploy the integration flow and check the execution and the data store in SAP Cloud Integration.

As we can see, we have retrieved data from the SAP Ariba APIs. We can now use this integration flow as a starting point when integrating SAP Ariba API with other services, e.g. SAP HANA Cloud, SAP BW/4HANA 2.0, Google's BigQuery.

You've made it to the end of the post 👏 👏. Thank you. I've covered how we can retrieve data from the SAP Ariba APIs and implement pagination in SAP Cloud Integration, by using the looping process call. I hope this blog post simplifies and accelerates your SAP Ariba integrations.
1 Comment