Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Imon12
Explorer
1,436

👋 Hello fellow tech explorers ! If you are new to SAP CPI and wondering how to start- you are  at the correct place! 

📖  Introduction

SAP BTP Integration Suite is a comprehensive suite of integration tools that includes Cloud Platform Integration (CPI), API management and more. In this blog, I will walk you through the step-by-step implementation of a simple Integration Flow that we implemented- a Weather Alert iFlow,  let's get started!

📌  Overview of the Business Scenario

The objective of the iFlow is to fetch weather data periodically from some public API and send an alert if the weather meets some predefined conditions like Temperature>35°C.  

✔️Prerequisites:  

1.An active SAP BTP trial account with Integration Suite subscription and corresponding roles assigned to it. 

Note- Refer to Get an Account on SAP BTP Trial for creating a SAP BTP trial account and refer to Set Up Integration Suite Trial for subscribing to Integration Suite service.

2. Create an account on any open source public API (here we are using OpenWeather API ) and get a free API key from the dashboard.

3. Ensure there is a Gmail account with OAuth 2.0 Authorization Code setup in SAP CPI.                                   

Note- Refer to SAP Integration Suite - IMAP and SMTP connection to Gmail with OAuth2 Authorization Code.

 

Now let's go through the steps to implement the iFlow in a SAP BTP trial account.

Step 1: Go to SAP BTP Trial  , click on Sign In, give required credentials and select Sign in.

             Imon12_1-1749387343708.png      Imon12_2-1749387602920.png

 

Step 2: Next "Go To Your Trial Account" have to be selected.

                       Screenshot 2025-06-08 184545.png

Step 3: Next we need to select the Subaccount and click Instances and Subscriptions under Services.

                                                 Imon12_3-1749387918627.png

                                                 

                                                 Imon12_6-1749392531107.png

 

Step 4: Choose Integration Suite under Subscriptions.                                             

                                                    Imon12_8-1749394379683.png

 

Step 5: Select Design → Integrations and APIs on the Integration Suite screen.

                                                                                 Imon12_7-1749393745196.png

 

Step 6: Package Creation

Now we have to create a package which is nothing but a container that stores and manages integration artifacts.

So we will select on Create button on the top right side of the Design screen.

                                                  Imon12_9-1749394717833.png

  

The below screen will appear where Name, Short Description fields needs to be mandatorily filled and Technical Name field will be autopopulated. After that,  Save button needs to clicked.

                                                 

                                                          Imon12_10-1749396875965.png

 

Step 7:  Integration Flow creation

Now we will be creating the iFlow within this artifact, so we need to click Artifacts →Add →Integration Flow .  A dialog box will appear; we have to fill Name and Description fields for the iFlow here.

                                                Imon12_11-1749398916252.png

After the fields are populated,  we can now create the iFlow after clicking on the Add and Open in Editor button.

 

Step 8: Addition of Elements for the iFlow

 a.  Timer Start Event- Every automation needs a trigger- so in this case we will first select the Timer Start which will basically decide when the iFlow will get triggered.  To make the iFlow easy, we have selected  On Deployment button which means every time the Deploy button is selected, the iFlow will get triggered.

🔃b. Request Reply - Next we will be using a Request Reply element which will basically request weather data through HTTP Adapter from  OpenWeather API (a free open source weather API).

🔌 c. HTTP Adapter and OpenWeather API HTTP Receiver - We use HTTP adapter and connect it to a receiver (renamed as OpenWeather API ) to fetch weather data. Under the Connection tab, we mention the API endpoint for the OpenWeather API in Address field, name of city with our unique API key from OpenWeather to access the data in the Query field and GET in the Method field as we are fetching the data from the API.

  

                                                    Imon12_12-1749405917921.png

✍️d. Groovy Script - Now that we have got the weather data, it's time to make sense of it. We will be using Groovy Script to do that. The Groovy Script will:                                                                                                                       

  • Read the JSON weather response from the API.
  • Extract the temperature   
  • Sets dynamic properties like temperature, isHot and condition for use in the rest of the flow.

Below is the code snippet that we used-

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.JsonSlurper
def Message processData(Message message) 
{
    //Body 
    def body = message.getBody(java.lang.String);
    def json = new JsonSlurper().parseText(body);
    def temp = json.main.temp;
    message.setProperty("temperature",temp);
    message.setProperty("isHot", temp > 35);
    message.setProperty("condition",(temp>35) ? "Hot" : "Normal");
    return message;
}

e.🔀Router- Now its time to make decisions- either alert would  be send or not based on the weather data fetched from the OpenWeather API; router element comes handy in such situations. 

If temperature from the weather API is above the set threshold , then  Send Alert branch is followed else the Default Route branch is followed,i.e. the iFlow gets ended.

 

f📃Content Modifier - Content Modifier is a powerful tool for enriching message data ,i.e., it helps to set or modify the message body, add headers etc. In this iFlow, we are using Content Modifier to prepare the weather alert message body with the inclusion of relevant static as well as dynamic values in the Body field and selecting Expression in Type field.

                                                        Imon12_14-1749413970178.png

 

 

g. 🔚End Event - The End Event after the content modifier in this iFlow properly finalizes the alert flow after the message body has been prepared in the content modifier. Once the alert message is sent, this End Event closes the flow.  Another End Event is connected to the default path of the router (which we selected after selecting the Default checkbox  for this branch).

 h. 📬Mail Adapter and Mail Receiver - The Mail Adapter and Mail Receiver work together to send email alerts in this iFlow. Under Connection tab, below details have to be filled:                                                                        

Address smtp.gmail.com:587 
Proxy TypeInternet
Protection STARTTLS Optional 
AuthenticationOAuth2 Authorization Code
Credential Name IS_GMAIL 

Note: IS_GMAIL is the name of the previously created OAuth 2.0 credential under security material.

We also need to define mail attributes like To,CC,BCC (Recipient/Recipients of the alert),  From (Sender of the alert) , Subject under Processing tab.

 

📧Mail Alert Example

On deployment, let's say the temperature of the city exceeds the threshold set, recipients will receive the below example email alert:

 

                                               Imon12_16-1749416166804.jpg

 

📸iFlow Snapshot

 

                                                          Imon12_15-1749415865879.jpg

 

📑Key Learnings 

  • Got a basic idea of different iFLow elements like Timer, Request Reply, Content Modifier etc.
  • Handle conditional logic using Groovy Script and Routers.
  • Format and send email content with Content Modifiers and Mail Adapter. 
  • Use CPI to automate external API calls.

If you have any queries or found this blog helpful, feel free to leave a comment here!

 

 

 

 

 

 

 

2 Comments
Swaita_Banerjee
Explorer
0 Kudos

Helpful Insights .

Imon12
Explorer