APEX Web Source Module: step by step

APEX Web Source Module: step by step

Published on: Category: Oracle


In this article, I will show how I created a Web Source Module in Oracle Application Express (APEX) that requires API-subscription-key authentication and a close inspection of the JSON-output of the Web Service.

If you are new to Web Source Modules or if you want to have a really detailed, step-by-step blog on how to set up a Web Source Module, have a look at: https://ujnak.github.io/APEX/creating_web_source_module/creating_web_source_module.html. Of course, you need an operational APEX Workspace if you want to try for yourself. If you don’t have one, you can get it on apex.oracle.com. Or use an Always Free cloud service.

Web Source Modules can be useful when you want to use data that are not located on the database server where APEX runs on. You can both read and write data using Web Source Modules.

In this example, I will create a Web Source Module that retrieves train station information from the Dutch Railway company (Nederlandse Spoorwegen). This company provides access to some of their data via an API portal. This API portal requires you to create an account (free) and subscribe to an API. Once subscribed, I can look up the Request URL of the API and authentication key.

Step 1: Create a Web Source Module

Let’s get started: create a new Web Source Module in the Shared Components in your application (or by pressing CTRL-quote and type “Web Source” and press enter).

Press the Create button. In the Modal Dialog, leave the radio group on “From scratch” and press Next.

I will create a “Simple HTTP” Web Source Module.

The URL Endpoint is basically the location from where the APIs are accessible. Press Next.

The Service URL Path specifies which API (and which version) we want to use from the endpoint. In this example, I’m using the places-api version 2.

Press Next.

Now, we have to configure the authentication that is needed to access the API.

Although authentication is required for the places-api, I’m going to finish the wizard by pressing the “Create Module Manually” button. The default authentication types in the wizard do not supply a request header configuration, and I got stuck a couple times using the “Advanced” button. Open the Web Source Module:

Next, press the “Add Parameter” button in the Module Parameters region.

I found the name of the HTTP Header parameter in the API description in the NS API Portal. The subscription key can be copied from the Profile page.

Step 2: Configure the Web Source Operation

The GET operation is already available, but it needs some adjustments. Edit the GET operation in the Operations region.

The URL pattern needs to be supplied to request the proper operation as described in the API documentation on the NS API Portal.

In this operation, I use 2 parameters: type and countries. I need these parameters, because I am now only interested in Dutch train stations. These parameters need to be added to the Operation Parameters:

For parameter “countries”, the value “NL” can be entered (with the quotes).

Step 3: Configure Data Profile

The last thing you need to do in the Web Source Module is to configure the Data Profile. This will map the JSON structure to column definition.

Press the “Edit Data Profile” button.

To find out what the row selector should be, you first have to inspect the JSON-result of the API-call. The JSON output shows a nested structure where we see a collection of “locations” within the value of “payload”.

This results in the Row Selector payload.locations

When the row selector is supplied, the available columns can be discovered by APEX by making an API-call. Press the Rediscover Data Profile. It will show a list of available JSON-field and makes a proposition for a set of new columns.

Press the “Replace Data Profile” to remove the existing (sample) columns.

Finally, press the Apply Changes button. With that, we are finished with the Web Source Module.

Step 4: Check your results

Now it’s time to test the Web Source Module. On a (new) page, create an Interactive Report. Choose Web Source as Location and pick the newly created Web Source Module.

Press “Save” and then run the page:

You can modify the layout of this Interactive Report (IR) just like any other IR. It’s also possible to make a Classic Report on the Web Source Module. It isn’t possible (yet) to make an Interactive Grid using the Web Source Module in this declarative way. However, if you are willing to tweak it a little, you should take a look at this blog: https://blogs.oracle.com/apex/web-source-modules-and-the-interactive-grid-part-1 

Note: in APEX 19.2, the use of a Web Source Module as a data source for the Interactive Grid is possible.

Debugging the Web Source Module

Unfortunately, there is no debugging option in the Web Source Module configuration page. If for whatever reason the configuration does not work as expected (especially the discovery of the data profile), you can create the Interactive Report (IR) with the (incomplete) Web Source Module and run the IR with debug on. This way, you can find relevant information about how the API call is made and what possibly the problem is.

Peter de Boer
About the author Peter de Boer

Peter de Boer is a consultant at Qualogy.

More posts by Peter de Boer
Comments (4)
  1. om 21:09

    Very nice Article! Thanks!

  2. om 08:08

    What if you wanted the field "HeeftFaciliteiten" too, which is a boolean. Do you know how to map that field to Data Profile and use the boolean value in the Apex app?

    1. om 08:08

      Hi Paul,

      The field HeeftFaciliteiten holds the values "true" or "false", but is actually a varchar2 field. The boolean data type cannot be used in the JSON data set, just like we can't use it in SQL.
      So you can use the field directly from the web source module and just display the values "true" or "false" as text in your report. You can also decode the values to Yes or No in the report by displaying the column as a select list and set Yes as display value and true as return value.

      Hope this helps

  3. om 09:09

    Thanks for sharing this great information I am impressed by the information that you have on this blog. Same as your blog i found another one <a href="https://smconsultant.com/training/oracle-database/oracle-apex-training/" rel="dofollow">Oracle APEX</a>. Actually I was looking for the same information on internet for <a href="https://smconsultant.com/oracle-apex-tutorial/" rel="dofollow">Oracle APEX Tutorial</a> and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject, you can learn more about<a href="https://smconsultant.com/oracle-apex-interview-questions-and-answers/" rel="dofollow">Oracle Apex</a>. By attending <a href="https:https://smconsultant.com/training/oracle-database/oracle-apex-training/" rel="dofollow">Oracle APEX Training </a>.