In this article, we are going to describe some of the recent enhancements that were made to the SAP OData application in IBM App Connect, and we’ll showcase how to exploit these features in a sample scenario.
We’ve added operators that you can use for date queries, and also now include OData-specific context information in SAP OData service responses to accommodate specialized use cases.
Operators for date queries
When building queries for SAP OData retrieve and update actions, you can now select
is greater than as operators while adding conditions with date fields. Any dates that are specified must be in a valid ISO date format.
Access to OData __metadata information
We’ve enriched the response that SAP OData services return to App Connect, to include OData-specific context information. SAP OData service response entries now contain an additional
__metadata field, which holds information that uniquely identifies a record in SAP. For more information about this field, see the OData documentation.
The following examples show XML and JSON formats for SAP OData service responses with the enriched data.
Example 1: XML-based response
In this response, an XML format was returned for this sample API call:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/">
<category term="TRANSPORT_TEST.Travelagency" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="TravelAgencies('88888888')" rel="edit" title="Travelagency"/>
Example 2: JSON-based response
For this response, a JSON format was requested in the sample API call to the OData service:
"NAME": "ABC Corp",
"STREET": "Church Street",
App Connect places the OData
__metadata information in an
odata_details object, but does not explicitly expose the object properties in the graphical mapper because they are not required for routine use cases, and require an understanding of OData metadata. If you have an advanced use case requirement for this information, you can access or expose it in either of the following ways:
- Using the JSON parser:
You can insert a JSON parser node into your flow to parse your SAP OData node response by providing sample output schema for your OData information, as shown in the following example:
You’ll then be able to directly map to the
odata_details properties in the JSON parser response.
- Using a JSONata expression:
You can directly add
odata_details in a JSONata expression by typing an expression or editing a mapping in a field; for example:
For any product in Salesforce, we want to extract from SAP, all business partner records that were added after a certain date. These business partners will be eligible for a product trial, and we’d like to send them a welcome email.
Let’s create a custom API that takes a product ID from Salesforce, queries an SAP OData service for eligible business partners, and then sends email notifications about the product to those business partners. Our flow definition will illustrate how to use the JSON parser to expose OData metadata information.
We start by creating an App Connect API flow with a simple model that defines two string properties called
Next, we create a custom GET operation that uses
salesforce_product_id as the ID of the custom operation:
To implement the flow for this operation, we first add a Salesforce > Retrieve products action after the Request node, and map the
salesforce_product_id model property to the Product ID. (When we run the flow later, we’ll specify an ID for the product record to retrieve.)
Next, add an SAP (via OData) > Retrieve BusinessPartnerSet action and define a filter that queries for business partner records whose
CreatedAt date in SAP is later than the
Created Date value of the Salesforce product retrieved in the previous action.
If the SAP Retrieve action returns an empty array with a status code of 400 (Bad Request), send this message to the Notification card:
No Business Partner Set eligible for the Product product_name
Otherwise, if matching business partner records are retrieved, iterate over each item of the
BusinessPartnerSet response, and then use the JSON parser to parse the item.
Then, add a Gmail > Create message action that sends a “Welcome mail from Salesforce” email to the business partner, with details about the product, and
odata_Details information. (This OData metadata information was exposed for mapping due to the JSON parser transformation in the earlier step.)
Finally, map to the status code of the SAP (via OData) > Retrieve BusinessPartnerSet response in the Response node of the API, and then start the flow.
The complete flow looks like this.
To test the flow, you can switch to the Manage tab to use the embedded API management capabilities in IBM App Connect on IBM Cloud. Expose and share the flow as an API, and then access the API Explorer window to use the built-in Try it utility to call the API. (For more information about using the embedded API management capabilities with an API flow, see the Managing APIs that are exposed by API flows in App Connect on IBM Cloud tutorial.) To call the operation, obtain the ID of an existing product in your Salesforce instance, specify this value in the salesforce_product_id field, and then click Call operation.
Here’s an example of the email message that a business partner might receive.