Weather Report Using Rest Web Service

Posted on Posted in SAP Business ByDesign

Save this article as PDF?

What is Rest Web service?

REST stands for Representational State Transfer, which is kind of easiest way to communicate with external systems in Cloud Solution. It is an architectural style for designing networked applications.

REST services provide a uniform interface using standard HTTP operations (such as GET, POST, PUT…) and exchange representations of resources. JSON and XML have frequently used formats in REST services.

So, I would like to document it here and let you know the same so that it will stay as a reference to everyone.


Tenant: SAP Business ByDesign.

Example: Weather Report (with Params).

Scenario: Integrate a simple weather API with SAP Cloud Solution.

Weather API: www.sankaranss.com/tutorial/rest/weather.php. For time being I created a sample API where it accepts one location parameter. I will keep this API open in case you want to try out. I used free resource for finding weather. So you can get only approximate weather while comparing with Google weather result.


Process Flow

  1. Create an External Web Service Using REST.
  2. Create A Communication Arrangement.
  3. Create A Custom Business Object.
  4. Create an action script.

Step 1: Create an External Web Service Using REST
  1. Login into the SDK. Select your solution from “My Solution” window.
  2. In the Solution Explorer, right-click your solution and select Add New Item.
    The Add New Item dialog opens.
  3. Select SAP Service Integration External Web Service Integration and click Add.
    The External Web Service Integration Wizard opens.
  4. In the Enter Web Service Name and Type step, enter a name for the Web service and select REST. Click Next.

1. rest create

  1. In the Enter End Point of REST Service step, do the following:
    • Enter www.sankaranss.com/tutorial/rest/ in the URL box. Click Next.
      The Host Address, Port, and Path fields are filled automatically.

1. rest create 1

  1. In the Define Communication Scenario step, do the following:
    • Select the Create Communication Scenario checkbox to create a communication scenario.
    • Enter a name for the communication scenario. It must start with a capital letter and can have 25 characters (letters, digits, and underscores).
    • Select the Allow Non-Secure URLs (HTTP) checkbox to allow non-secure communication.Click Next.

1. rest create 3

  1. On the Review page, review your entries and click Finish.

1. rest create 4

  1. In the Solution Explorer, an external Web service integration file WeatherReport01.wsid and a communication scenario definition file WeatherReport01.csd are displayed. Save and Activate both the files.

1. rest webservie looks

A communication scenario and a communication system (The communication system is created automatically) are generated in the SAP cloud solution. These can be used to create a communication arrangement.


Save this article as PDF?


Step 2: Create a Communication Arrangement

To test the communication scenario, you need to create a communication arrangement in the SAP cloud solution.

  1. In the studio, in the Solution Explorer, right-click the communication scenario definition (WeatherReport01.csd) file and click Manage Communication Arrangement. 

2. arrangement rest webservice sap byd

  1. Log on to the SAP cloud solution.
    The Communication Arrangements work center view opens.
  2. Click New.
  3. The New Communication Arrangement view opens.
  4. In the Select Scenario step, select the communication scenario WeatherReport01 which you have created in the studio and click Next.
  5. In the Define Business Data step, select the System Instance ID as “WeatherReport01 and click Next.

2. arrangement 1 rest webservice sap byd

  1. In the Define Technical Data step, Click Edit Advance Settings Button do the following:
    1. Uncheck “Use Basic Setting
    2. Application Protocol: Http
    3. Set Protocol as Hypertext Transfer Protocol(http).
    4. Host Name: www.sankaranss.com
    5. Port: 80
    6. Path: /tutorial/rest/weather.php
    7. Authentication Method: None
    8. Click Next.

2. arrangement 3 rest webservice sap byd

  1. In the Review step, review your entries and click Check Completeness. Then click Finish and close.

To Test Rest web service

  1. Choose Communication Arrangement (WeatherReport01) -> Technical data -> Edit Advance Settings -> Check Connections. If you see a message as “Ping Successful”, your rest service is perfectly working.
    2. arrangement test rest webservice sap byd
  2. If you see any error message, first check your URL and port number.

2. arrangement test error rest webservice sap byd

  1. If you have done any modification in URL or in any other options, you have to click “Save and Reactive”, before clicking “Check Connection”.

Step 3: Create a Custom Business Object

Integrate the Weather Report with SAP Business ByDesign.

  1. Create a custom Business Object WeatherReport.
  2. Define elements as shown in the below screenshot.
  3. Save and Activate.
    For more information about the Custom Business Object creation, see http://blog.sankaranss.com/2016/03/29/sap-byd-business-object/.

3.bo rest webservice sap byd

  1. Create screens for the WeatherReport BO and Design it.
    For more information about the Screen creation and Design, see http://blog.sankaranss.com/2016/04/28/sap-byd-screen-types/.

Save this article as PDF?


Step 4: Create an Action Script
  1. Create getWeather Action script file for WeatherReport BO.
    For more information about the Action and Events, see
    http://blog.sankaranss.com/2016/04/11/sap-byd-actions-and-events/.
  2. Copy and paste below code.

import ABSL;
// Communication details
var ScenarioName = “WeatherReport01”;
var ServiceName = “WeatherReport01”;
var HttpMethod = “GET”;
var HttpResource = “weather.php”; //URL – File Name
// not required for this example
var ContentType = “”;
var Body = “”;
var HeaderParameter : collectionof NameAndValue; // Set URL Parameter

var URLParameter : collectionof NameAndValue;
var URLParameterEntry : NameAndValue;
URLParameterEntry.Name = “location”;
URLParameterEntry.Value = this.location;
URLParameter.Add(URLParameterEntry);

// Execute webservice call
var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);
//Parse result of Web service and retrieve city name; you may have to adapt the logic to the Web service used
this.WeatherResult = ws_result.Content;

  1. Save and Active.

Finally, your files look as like below screenshot.

3. script rest webservice sap byd


Step 5: Testing
  1. Log in as a business user.
  2. Navigate to the QA Screen by creating a custom BO instance.
  3. Enter the location. Ex. Bangalore,IN
  4. Click Get Weather
    You can see Weather Report in Result area.

5.testing rest webservice sap byd


We have seen about integrate weather report with ByDesign using Rest Web service, and in the future article, we will learn more about it. Don’t forget to subscribe my blog and leave your comments to improve this article.

If need to download this article as PDF?

4 thoughts on “Weather Report Using Rest Web Service

  1. Sanakaran,
    Thanks a lot for the guide. Informative and fun.
    Is your API still up and running? I get the following html markup when submitting my location( Knoxville, TN).

    IIS 8.5 Detailed Error – 404.0 – Not Found

    HTTP Error 404.0 – Not Found
    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    Most likely causes:
    The directory or file specified does not exist on the Web server. The URL contains a typographical error. A custom filter or module, such as URLScan, restricts access to the file.

    Things you can try:
    Create the content on the Web server. Review the browser URL. Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.

    Detailed Error Information:

    Module   IIS Web Core
    Notification   MapRequestHandler
    Handler   PHP-php
    Error Code   0x80070002

    Requested URL   http://www.sankaranss.com:80/tutorial/rest/weather.phpweather.php?location=Knoxville%2c%20TN
    Physical Path   D:\Inetpub\vhosts\redhotstudios.in\sankaranss.com\tutorial\rest\weather.phpweather.php
    Logon Method   Anonymous
    Logon User   Anonymous

    More Information:
    This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
    View more information »

Leave a Reply

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