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.

Enhancements

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 equals and is greater than as operators while adding conditions with date fields. Any dates that are specified must be in a valid ISO date format.

SAP OData date operators

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:
http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/TravelAgencies

<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/">
<id>
http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/TravelAgencies('88888888')
</id>
<title type="text">TravelAgencies('88888888')</title>
<updated>2019-07-03T10:43:12Z</updated>
<category term="TRANSPORT_TEST.Travelagency" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="TravelAgencies('88888888')" rel="edit" title="Travelagency"/>
<content type="application/xml">
<m:properties>
<d:agencynum>88888888</d:agencynum>
<d:NAME>UpdateorcreateTia</d:NAME>
<d:STREET>appconqx6xx</d:STREET>
<d:POSTBOX>appconw6c2</d:POSTBOX>
<d:POSTCODE>appconqecf</d:POSTCODE>
<d:CITY>appconkfbh0gk</d:CITY>
<d:COUNTRY>Ind</d:COUNTRY>
<d:REGION>app</d:REGION>
<d:TELEPHONE>appconeuok8n</d:TELEPHONE>
<d:URL>http://www.ervcnve.com</d:URL>
<d:LANGU>a</d:LANGU>
<d:CURRENCY>app</d:CURRENCY>
<d:mimeType>text/html</d:mimeType>
</m:properties>
</content>
</entry>

Example 2: JSON-based response

For this response, a JSON format was requested in the sample API call to the OData service:
http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/TravelAgencies?$format=json

{
    "d": {
        "__metadata": {
            "id": "http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/TravelAgencies('88888888')",
            "uri": "http://203.0.113.0:8000/sap/opu/odata/iwbep/TRANSPORT_TEST/TravelAgencies('88888888')",
            "type": "TRANSPORT_TEST.Travelagency"
        },
        "agencynum": "88888888",
        "NAME": "ABC Corp",
        "STREET": "Church Street",
        "POSTBOX": "",
        "POSTCODE": "560098",
        "CITY": "Bangalore",
        "COUNTRY": "Ind",
        "REGION": "AP",
        "TELEPHONE": "183201020",
        "URL": "http://www.abc.com",
        "LANGU": "EN",
        "CURRENCY": "INR",
        "mimeType": "text/html"
    }
}

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:

Scenario

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 salesforce_product_id and statusCode.

Next, we create a custom GET operation that uses salesforce_product_id as the ID of the custom operation:
GET /Salesforce_To_SAP/:salesforce_product_id/geteligiblebusinesspartnerset.

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.

Join The Discussion

Your email address will not be published. Required fields are marked *