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.
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.
To find out how to create a trial account: https://developers.sap.com/tutorials/hcp-create-trial-account.html
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...
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. |
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.
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
}
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
4 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |