This document explains how we can use a Rest API URL to connect as a data source. Here we will explain both the GET method and the POST method for interacting with the data source.
Note: As of version 2020.12, we support the rest APIs returning the data in JSON or CSV formats.
Basic Get Method:
We use the basic GET method to retrieve data from an API. The steps required to retrieve that data are as follows-
- Select a query chain with which you want to interact and fill in the details. Ensure to select the folder path where you want to save it.
- Select the Rest API widget and configure it according to the requirements.
In the above example we
- Select the method as "GET".
- Put in the URL of the API that we want to use.
- Select the response type. In this case, it is JSON. (We also support CSV format)
- You can add parameters if you have any.
In the above example, we are adding parameters to select objects having userid as 1 and id as 5. So the result will show only that data.
- You can add the headers that you want to display.
In the above example, we are adding the headers userid with value 1 and id with value 3, so the relevant data will be displayed in the output.
- Click on "GET" JSON Data button to get the data.
In the resultant output, you can either select the entire array or one particular object to be displayed in the output. By default, the entire array is selected.
- After selecting the output that you want to display, you can click on Preview Data, to preview the details of the selected data. By default, the first hundred rows are displayed.
- After a preview of the data, click on ‘Save’ to save the API.
- You can then use transformations to make changes to the results.
In the above example, we are using Projection to transform the data type of the selected columns. You can even perform mathematical functions through projection as follows.
We support the following mathematical functions
- String Functions
- Numeric Functions
- Time and date functions
- Case Expressions
You can then add a filter, to filter out data. In the following example, we are filtering data having userid equal to 1.
- Then add the rd output and Select it to see the results
- After saving the entire setup, click on run.
The above data will be retrieved from the data source based on the API configured.
Basic Post Method:
We use the basic Post method to update an API. The steps required to update the data are as follows.
- Select the query chain.
- Select an API widget to be configured.
In the post method, it is necessary to add the content of the body as we have to mention the parameters to be updated there.
In the above example, we are updating the data having userid as ‘1’ and id as ‘11’. The output will be as follows –
- Select transformations that you want to apply.
- Select the RD output to view the results.
- Save and execute.
Pre-request API
In a few APIs, we need to use a token to access the actual data. The pre-request API feature helps you to achieve this. In the case of pre-request API, we should use the ‘Post’ method always, as we need to update the API. You need to do the following to configure the pre-request API.
- Click on the API widget.
- Click on the tab titled pre-request API and the following window will appear.
- Select the method as Post and paste the URL of the API. Then click on the tab title Body.
- Paste the data to be parsed in the body tab.
You can use the button titled “Beautify” to keep the pasted text in proper syntax. Select the option in JSON format.
- Click on Send.
Select the Access token from the list of parameters that appear. (In this example we have only the access token, sometimes this screen may contain the list of other parameters that have been passed to be updated, so you should select only the token.)
- The token details get updated in the Authorisation tab and the Headers tab. This token generated from the pre-request API tab falls under the bearer token category of the Authorisation tab.
- Click on GET JSON Data
- Select the output that you want to display. (Either the entire array or one particular object). Here we are selecting the entire array.