Integrating a REST Web Service That Returns JSON Data
- Updated on 11 Mar 2019
- 3 minutes to read
The Decisions portal can integrate with web services that return JSON formatted data.
The steps for retrieving and using the JSON data are as follows:
- Integrate the service within the Decisions portal
- Create a flow to make the service call and handle the results
- Generate a data type to deserialize the JSON data so it is usable and introduce that type into the flow
In this example, a web service that retrieves weather is integrated with the Decisions portal. An XML data type is generated against the web service's return data structure, and a flow is created to make the service call and handle the results.
Integrating the Web Service
Log in to the portal (with an administrator account). Navigate to System > Designers > Integrations > External Services.
Select Add REST Service Integration. In the Service Name field, type the name of the web service then in the Service URL field, paste in the URL. Most likely, the URL will contain variables to pass in; those will be moved to a new field after the following settings are established. For example purposes we are using: https://slack.com/api/api.test
For this example, change the Service Input Method field value to Get. Change Service Content Type to Json.
Select SAVE to complete setting up the RESTService Reference.
Using the Web Service Call in a Flow
Create a new flow that will make the call to the web service and ingest the return data. From the Designer Folder , select Create Flow. Name the new flow and select OK.
From the steps panel expand Integrations > All Integrations > Rest Service category, and select the API Test component. Select Add to add it to the workspace.
The output of this web service call will be a string of serialized JSON data.
In order to use the data returned in a more meaningful way, it is necessary to create a data structure for the data.
Save and close the flow.
Create Data Structure From JSON
From the Designer Folder , select Create Datatypes > Create Types from Json.
In this example, we simply paste in the structure when creating the data type. There is also potential to upload a the structure through a Json file.
Enter a name for the service in the JSON Structure Name field, and either upload a file for the structure or paste in the data structure. In the list of recognized data types from the structure, select the desired types.
Select SAVE STRUCTURE. The data structure is generated for the JSON data, as well as components for deserializing and serializing that data.
Deserialize JSON Data
Next, it is necessary to introduce the Deserialization step into the flow to break down the JSON string into meaningful, usable data.
From the Designer Projects folder, open the flow that contains the API Test service step.
From the Steps panel, expand the Data > JSON category.
Drag and drop the Json Deserializer step following the API Test step. Connect the outcome paths as pictured below.
Select the Json Deserializer step. In the Properties panel under Input, change the mapping type for String to Deserialize to Select from Flow. Select Select from Flow in the Pick Data dialog and chose Done and select Pick. This is the output from theAPI Test step.
Expand the Data Explorer (left-handed side of studio), notice how the deserialized output is available.