REST Action
  • 13 Minutes to read
  • Dark
    Light
  • PDF

REST Action

  • Dark
    Light
  • PDF

What are Actions in Rivery?

Actions are the ability to connect anywhere on the web.

The REST Action is the place to send REST requests in order to get data from Web services (APIs etc.) or post data in Web services.

Create a REST Action

Click on “Create new river” from any screen in Rivery and select the “Action” option.

An action in Rivery can be Multi-Action or a single REST Action.

  • Multi-Action is an action that is composed of multiple REST Actions, which allows for a single workflow with multiple endpoints, and the passing of values between endpoints.
  • REST Action is a generic process that can be configured to send any kind of REST request. 

Click on Rest Action in order to proceed to the REST Action screen.

The REST Action is composed of two major parts: Request & Results.

In addition, the REST Action has its own Custom Connection, its own Variables, and Time Period inputs.

  • Request Configuration has options to insert all the inputs related to the request of the REST Action such as the URL, parameters, headers, and more.
  • Results Configuration contains the options for handling the results of the REST request.
  • Custom Connection is an optional input to define the connection of the action. This connection can be reused in multiple Actions. All the details of the selected custom connection will be added to the variables of the action and can be encrypted in the connection.
  • Variables menu allows for defining variables to be used in the Action. Variables can be used in any input in the Action.
  • Time Period allows for defining a time range of the rest action. Select the type of the dates (DateTime or Date), and select the time format which is required for this request. Once a time range is defined, corresponding variables {time_range.start_date} and {time_range.end_date} will appear in the Variables menu. 


Custom Connection

Create or select an existing custom connection.

It is possible to leave the connection empty in case it is not required.

The keys in the connection can be encrypted by using the Is Password checkbox:

Request Configuration

The Request section contains all the required settings for sending a proper REST request.

In any of the inputs, it is possible to use the variables that were configured in the Variables menu.

  • API URL: The HTTP address of the service. This should start with “http://” or “https://”. If the request has parameters, these can be managed in the Params inputs. 

  • REST method of the request. Rivery currently supports in GET, PUT, POST, PATCH, and DELETE requests.
  • Params - Click on the Params button in order to add parameters to the request.
    Click on the Add button to add the required parameters and their corresponding values. Important: The key of each parameter must be equal to the name of the parameter that the service is expecting.
    The value of each parameter is the exact value that will be sent in the request. It is possible to use variables as values.
  • Authentication type - In some requests, it is required to add an authentication method to the request. Rivery currently supports Oauth2.0, Basic Auth, and No Auth. Use the 'No Auth' option if the API only requires some sort of authentication through the Headers, Parameters, or in the API URL.
  • Headers - The headers that will be sent in the request. (Leave this empty if no headers are required). 
  • Request Body (Available in all requests except "GET") - The body that will be sent in the request. The text must be in JSON format.

Advanced Options 

Optional parameters that are not required when submitting a REST request but may be beneficial in some instances:

1. 'Sleep After Request' - Set the amount of time Rivery will wait after sending the request.

2. 'Timeout_request' - specify the amount of time to wait for a response. The Action will return an error if the provided time has passed. The default waiting time is 300 seconds if the input is left blank.

3. 'Validate Http Certificate' - The Http/Https certificate will not be verified if this option is unchecked. Mostly used to obtain data from internal APIs.

Warning:

This is a less secure connection method, use it at your own risk.

Testing the Request

Once the request is configured, try the “Test Rest Action” button to determine if the request returns a successful response. This will send the request with all the configurations inserted in the request section and will return the response that was received for this request in the user interface.

If there is an error in the response it will be shown with the corresponding error code and the error message received from the API.

Results Configuration

The Results section contains all the required settings about how to get the results from the response that was received from the REST request.

Rest Actions can return one of the following types of results:

  • Response - The action will only return the response code for the given request. If selected, no options will be shown except the advanced options. This option is most commonly used with POST and PUT calls.
  • Variables - The action will return variables that store the values that were returned in the request’s response. This kind of action can be used inside a Multi-Action or a Logic River.
    Data Location (Available only if the Results Type is set to Variable or Data)
    Insert the key in the response where the desired results are located. If the required data is the whole response, leave the data location empty. If the data is located in a nested key, use ‘.’ to indicate it.
    For example, If the response looks like this and the desired results are in the 'data' array:
     {‘results’:{‘data’: [....], ‘status’: ‘success’}}
    The data location would be “results.data” to obtain only the response data located in the 'data' array.
    Important
    The Data Location input uses standard JSON Path format as outlined here: https://github.com/json-path/JsonPath#operators.

    Data Position (Available only if the Results Type is set to Variable or Data)

    If the desired response is a JSON array and the required results are located in one of the elements, the data position should be set to the position of that item (starting from 0). If this is not the use case then leave this option empty.

   Variables to return (Available only if the Results Type is set to Variable)1. Click on “Add” to add variables to return.

2. Name of the output variable to return - Insert the desired name of the variable.

3. Key in the response - Insert the key in the response that contains the value to be stored in the variable. Leave this empty to store the entire response in the output variable.
Use ‘.’ notation if the value for this variable is located in a nested key in the response.

Example:
We would like to send a request to generate a token and return this token as a variable called new_token.
The response is:

Text
{"auth_res": {"token": "abcde12345", "expired_at":"2017-07-01 22:00:00"}}

In the data location input, we’ll insert auth_res (because the data we are interested in is located inside auth_res).

In the variables to return we’ll add a new variable with key: new_token and value token.

  • Data - The action will return data that can be loaded into a Rivery-supported target. This is most commonly used with GET calls, and requires creating an additional Data Source to Target river, with the source set to 'REST API'. For this use case, the Action is used as a template for the Source to Target ingestion.


Results Details - (Available only if the Results Type is set to Data)

Select the results structure -

1. JSON Structure: If the data is in JSON structure (meaning a list of rows when each row is an object of key-value pairs)

*CSV In A JSON Format - If the response is returned as JSON data, but the results data are in a CSV structure (as in the example below the toggle button in the screenshot) it is necessary to indicate where the headings of the data are located (fill the key of the JSON response - for example, headers ).

Note that this option requires filling both 'Headers Location' and 'Data Location' inputs.

2. CSV Structure: If the data is in a table structure. CSV can be the whole response if the response is just text or can be split to a key in the response which stores the heading and values separately.


If CSV is selected, it is necessary to indicate where the headings of the data are located. If the headers are in the first row of the data, keep the 'First row in values is headers' toggle enabled. If the headers are in a different row, disable this toggle and fill in the header row number.


Pagination Details (Available only if the Results Type is set to Data)

Some services return the data in pages (also known as chunks) and require extra logic for 'paging' through the results. Pagination is the mechanism for pulling all of the results from the service if it is returned in pages.

Important:

The selected pagination will be in actual use only when running the action from a REST Source to Target River. When running the action, it will return only the first page as a sample of the data.


Pagination Methods

The REST Action supports the following pagination methods:

Paginate by offset

This pagination method expects that there is some way to get data based on an 'offset' or sending in a value for the starting point of the pull.

  1. Offset start - The start position for pulling the data (typically this is 0 or 1).

  2. Offset key - The name of the key where to send the offset in the request (most of the time called 'offset')

  3. page_offset variable

    Enable the page_offset variable option when the REST API request requires different usage of an offset value than the typical 'offset' = N in a request URL parameter.

    For example - the REST request should be sent as POST method and the offset variable has to be sent in the request body. Use the page_offset variable in the request body with {page_offset} and the river will replace it with the offset value when iterating over pages.

    image.png

    Paginate by page

    This pagination method splits the response data into pages, and each request contains the page number to pull, usually starting from 1.

    Page key - The name of the URL parameter to update (usually called 'page').

    page_value variable

    Enable the page_value variable option when the REST API request requires the page value to be updated somewhere other than a URL parameter (such as the body or just an increasing number in the URL itself).   


    Next page in response

    Each response contains the details of the next page to pull.

    In this method, we need to indicate where to find this information in the response.

  • Next Page Type

1. Static URL with param from the response

The response contains some value to be sent in the next request in order to pull the next page. The next request can be sent with the initial URL or with a new URL.


Next page key - the key in the response which contains the value to be sent in the next request.

Send next page in key - the parameter’s name in the next request to send the value of the next page.

Next page in new URL - The URL to send the pagination requests with. Leave empty if using the same URL.

  • Url in response

The response contains a full URL ready to be sent to get the next page’s data.

Next page key - the key in the response that contains the URL of the next page.

Next page prefix - if your next page does not contain the URL prefix, it can be added here. 

Example:

In the above snapshot, the next page cursor is found in key next_cursor, and we will use it in the next query parameter key _cursor. I.e.,

GET {url}?limit=50

response = {'data_to_yield': [....], 'next_cursor': 'df3DFsdffs3'}

Next paginated request:

GET {url}?limit=50&_cursor=response['next_cursor']

Stop according to

Select how to determine when the paging will end. 

  1. Page size - the pagination stops when the page size (in records) is smaller than the value that was inserted to the input of page size. 

Key in response - the pagination will stop when the response contains a given value in a given key.


1. Insert the name of the key in the response which is supposed to contain the value. If the data is located in a nested key, use ‘.’ to indicate it.
2. Insert the value that should cause the paging to stop.

Sleep after each page
Hold the process for the given amount of seconds.
It is recommended to use that input in order not to overload the service with too frequent requests when using pagination.

Results Advanced Options

Replace invalid characters in headers

Add Dates Variables to Results Data

This option will take the values passed through Time Period variables ({time_range.start_date} and {time_range.end_date}) and automatically populate them in the Column Mapping of the Data Source to Target river when the Action is set as the Source. This is especially useful for use cases where dates are required input parameters but the corresponding response data does not include the date values.


Additional Advanced Options:

Insert the number of seconds to hold the process. Insert the name of the key in the response that is supposed to contain some value. Insert the value that should cause the process to hold.

  • Insert the number of seconds to hold the process. Insert the response code that should cause the process to hold.

  • Insert the key in the response that is supposed to contain the value. Insert the value that should cause the process to exit.

  • Insert the response code that should cause the process to exit.

Send a request in a loop

Designed for iterating over API requests


Keys to monitor

Insert any key in the response that you’d like to monitor during the Action’s run.

If the Action found that key in the response it will store its value and will return it in the action results and also in the activities screen (when opening the action details).

The keys to monitor can be useful when the response might contain messages about errors or the runs.

In that case, if the action failed, thanks to the “keys to monitor” you’ll have some information about the error when opening the action results in the activities screen.

Testing the results

Once the results are configured, it is a good time to test the REST Action. This test will consider all of the configurations of the Action results, such as data location and position.

Variables

The Variables menu is available on the top right of the Actions screen.
Insert as many variables as required. These can be used as placeholders for dynamic values to be sent to the Action by a Logic River. In a Logic Step, an Action can be called and any variables defined will show up as possible input parameters.

Time Period

The time period allows for defining a start date and end date of the request and is available by selecting the Time Period menu in the top right of the Action screen:


These two parameters will be automatically added to the variables list of the action and can be used anywhere in the action (usually will be sent as parameters in the request).

The time format input decides how those dates, when used in the action, will be sent in the request - this format should be the expected format of the service to which the request is being sent to.

If the required format is not in the list of the time formats, it is possible to insert manually the required time format according to python syntax.

Creating a dynamic date range

In order to pull a dynamic date range, select 'Time Period' on the top right of the Action screen and define the date format and initial start and end values:

  1. Set the date period:

  2. This will add two new parameters in the variables section:

  1. Create a new Data Source to Target river and choose the REST API as the source. Then choose the desired date range:

Rest Action That Returns Data

If the Action is meant to get data into a Rivery-supported target, this will require the creation of an additional Data Source to Target river, with the source connection set to 'REST API'.

In the Source tab of the Data Source to Target river, select the corresponding REST Action as the source. If any Time Periods or Variables were used as part of the configuration, these will be made available in the Source tab.

Finalize the REST Action

Once the test of the Action returns the expected results, the Action is ready to be used. 

The Action created can be used in any of the following rivers in Rivery:

  1. Data Source to Target River (only if this REST Action has “data” results type)

  2. Multi-Action River

  3. Logic River



Was this article helpful?

What's Next