REST API
Last updated
Last updated
A REST API is an application programming interface that conforms to the constraints of REST (representational state transfer) architectural style and allows for interaction with RESTful web services.
REST APIs work by fielding requests for a resource and returning all relevant information about the resource, translated into a format that clients can easily interpret (this format is determined by the API receiving requests). Clients can also modify items on the server and even add new items to the server through a REST API.
The REST API source support batch syncs.
You can find the parameters in the Info tab below (Image 1).
Title
Mandatory. Input a name for your data sync
REST API Sync
Variables
Optional. Review our documentation on Variables here for more information about this field.
Permissions
Data syncs are role based access systems where you can give specific groups read, write, execute, and/or all of the above with admin access. Inputting at least an Admin Group is mandatory.
Mandatory and optional parameters for the Source tab are outlined below (Image 2).
Source
Mandatory. Select your source from the drop down menu.
REST API
HTTP Method
Mandatory.
This will be either GET or POST.
API Response Format
Mandatory. Use this field to specify a response format of the endpoint. Currently, the Connections UI only supports JSON responses.
JSON
Records Root JSONPath
Mandatory. Specify the JSON path for the results. The root of a JSON object is $
. If the top-element of the response is an array, Cinchy places the array under a "data"
key in a new JSON object. See Best practices for more info.
$.data
, $
, $.ResponseObject
Path to Iterate
The path to select an array of records for capturing elements inside. A record is created for each element which you can use as the input in a source schema. The path is relative to the root JSONPath.
API Endpoint URL
Mandatory. API endpoint, including URL parameters like API key
https://www.quandl.com/api/v3/datatables/CLS/IDHP?fx_business_date=2024-01-01&api_key=@API_KEY
Next Page URL JSONPath
Specify the path for the next page URL. This is only relevant for APIs that use cursor pagination
To get fields in a nested array, you can either set the nested array as the root, or you can use Path to Iterate to expand the array.
Here is a sample JSON response:
Records Root JSONPath: $.users Schema:
$.userId
for ID
$.name
for Name
You can't reference "groupId"
as it's one level above the specified root scope.
Use $.data
in Records Root JSONPath if the API returns a top-level JSON array.
Here is a sample JSON response:
Records Root JSONPath: $.data
Schema:
$.name
for Name
$.age
for Age
Use Path to Iterate to expand and target nested keys within the array. This only applies if the records within an array are objects.
If the record within the path to iterate is an array, each item within the array gets placed under an "item"
key in a new JSON object.
For example, here is a sample JSON response:
In this example, we want to iterate over the "transactions"
array and capture the records for "transactionid"
and assign them to the "Transaction ID" column, and then add the parent "name"
key to a Name column .
Records Root JSONPath: $
Path to iterate: $.transactions
Schema:
$.name
for Name
$.transactions.id
for Transaction ID
Configure your Destination
Define your Sync Actions.
Add in your Post Sync Scripts, if required.
To run a batch sync, select Jobs > Start Job
For more information, see the page about auth requests.
For more information, see the page about request headers.
You are able to use this section to add body content.
A pagination block is mandatory. Review the documentation here for more on pagination blocks.
Retry Configuration automatically retries HTTP Requests on failure based on a defined set of conditions. This provides a mechanism to recover from transient errors, such as network disruptions or temporary service outages.
Note: the maximum number of retries is capped at 10.
To set up a retry specification:
Under the REST API source tab, select API Specification > Retry Configuration
Select your Delay Strategy.
Linear Backoff: Defines a delay of approximately n seconds where n = current retry attempt.
Exponential Backoff: A strategy where every new retry attempt is delayed exponentially by 2^n seconds, where n = current retry attempt.
Example: you defined Max Attempts = 3. Your first retry is going to be in 2^1 = 2, second: 2^2 = 4, third: 2^3 = 8 sec.
3. Input your Max Attempts. The maximum number of retries allowed is 10.
Define your Retry Conditions. You must define the conditions under which a retry should be attempted. For the Retry to trigger, at least one of the "Retry Conditions" has to evaluate to true.
Retry conditions are only evaluated if the response code isn't 2xx Success.
Each Retry Condition contains one or more "Attribute Match" sections. This defines a regex to evaluate against a section of the HTTP response. The following are the three areas of the HTTP response that can be inspected:
Response Code
Header
Body
If there are multiple "Attribute Match" blocks within a Retry Condition, all have to match for the retry condition to evaluate to true.
Note that the Regex value should be entered as a regular expression. The Regex engine is .NET and expressions can be tested by using this online tool. In the below example, the Regex is designed to match any HTTP 5xx Server Error Codes, using a Regex value of 5[0-9][0-9]
.
For Headers, the format of the Header string which the regex is applied against is {Header Name}={Header Value}
. For example "Content-Type=application/json"
.
;;