Set up Write, Filter and Get tasks in SAP Cloud Integration to save, filter and get your needed message to execute other operations in your Integration Flow

Hello!

This blog post belongs to a Tutorial Blog Post series about where its simulating a sales transaction on buying a new refrigerator using a SAP AppGyver custom app, while consuming different SAP and 3rd party services.

In the previous blog post we set up the Stripe Connector from SAP Open Connectors to trigger payment transactions using SAP Cloud Integration.

Tutorial Blog Post Series – Sections

They are divided into several blog posts to not make it so bigger in one alone.

  1. Build an integral SAP Integration Suite project and consume it from a SAP AppGyver custom app – Tutorial Blog Post Series Introduction [Link]
  2. Consume a Stripe service from SAP Open Connectors and SAP Cloud Integration to create payment transactions [Link]
  3. Set up Write, Filter and Get tasks in SAP Cloud Integration to save, filter and get your needed message to execute other operations in your Integration Flow [Here you are in this blog post]
  4. Consume a SAP Sales and Service Core API to create Sales Orders using an OData receiver adapter in SAP Cloud Integration (soon to be published)
  5. Send application/x-www-form-urlencoded parameters to a HTTP receiver adapter in SAP Cloud Integration to send SMS messages consuming a Twilio API (soon to be published)
  6. Integrate SAP AppGyver with SAP Integration Suite, consuming an Integration Flow levering SAP API Management policies (soon to be published)

Let’s start

As SAP Cloud Integration works with XML and the expected payload from Open Connector/Stripe is in JSON, we need to add a JSON to XML converter in order to store the initial payload from AppGyver in CPI and retrieve it when the payment transaction is successfully done.

We are not going to use the root generated by CPI, so let’s uncheck the box.

Now let’s add a “Write” task to store the initial payload we are going to send from AppGyver. Select it from the cube “Persistence” and “Data Store Operations”.

To make it consistent add:

  • Data Store Name: AppGyverSavedPayload
  • Visibility: Integration Flow
  • Entry ID: message1
  • Retention Threshold for Alerting (in days): reduce it to 1 day.
  • Expiration Period (in days): reduce it to 2 days.
  • And uncheck the “Encrypt Stored Message”. For this exercise we are not going to encrypt the message, but in real life it is highly recommended.

Like this:

As we only need to send the payment data to stripe, we are going to add a Filter. As this is the Payload I’m using, I need to add this Xpath Expression: /AppGyverSalesOrder/paymentData and select Nodelist as the Valuetype, as we use are using lists in the payload.

{ "AppGyverSalesOrder": { "customer": { "ObjectID": "<Object ID from SAP C4C>", "BuyerPartyID": <BuyerPartyID from SAP C4C> }, "paymentData": { "amount": <Payment transaction amount to be processed in Stripe>, "customer": "<stripe customer id>", "currency": "<currency selected in stripe account>", "source": "<card id>", "description": "Test payment via CPI" }, "product": [ { "ProductID": "<Product ID from SAP C4C>", "Quantity": <Product quantity to be purchased> } ] }
}

Note: Bear in mind that the “customer” and “product” objects are included as part of the whole scenario. We’ll need them for requesting SAP Sales and Service Core a sales order creation, which we’ll see in the next blog. For now, I want to show you how with Write, Filter and Get tasks you can use only the data you need to execute other operations.

It should look like this:

Now, we need to convert the XML payload to JSON, as it is how Stripe needs it in order to generate the payment transaction. Make sure you select UTF-8 as the JSON Output Encoding, and check the box in “Suppress JSON Root Element” (this is important to be able to enter the data inside the XPath Expression without the “parent” object:

If you want, you can test on Postman if the payment transaction is still working, use the Payload structure as I put it above, just change it to your data. You should be able to generate the payment transaction.

Check the trace:

Now we are going to add a Get task to retrieve the initial payload. You have to put the same name and entry ID as you did in the Write task. Check the “Delete On Completion” box, to delete the storage message when the iFlow transaction is completed.

You can test again if you want to, you should see the whole initial payload as it was saved with the Write task:

Remember to activate the Trace log after deploying your iFlow. Go to the Monitor Message Processing and Trace.

Now, you have successfully retrieve the initial payload using Write and Get task, plus learnt how to filter data using Filter task and XPath expressions.

Following the Tutorial Blog Series, we now need to configure the SAP Sales and Service Core API consumption to create Sales Orders. For this step, check out this next blog: Consume a SAP Sales and Service Core (SAP C4C) API to create Sales Orders using an OData receiver adapter in SAP Cloud Integration (soon to be published).