REST API
Last updated
Last updated
The REST API Target functions differently than the others, the initial page looks like this:
Under API Specification, the options are REST API Source, Insert Specification, Update Specification, Delete Specification:
Cinchy v5.5 added support for the URL_ESCAPE and JSON_ESCAPE functions to be used in REST API data syncs anywhere a "parameter" could be utilized (Ex: Endpoint URL, Post Sync Script, etc.). These functions escape parameter values to be safe inside of a URL or JSON document respectively.
This functions almost identically to the REST API Source, with the same parameters.
However, four different sections can also be added:
Parameter
Value
httpMethod
GET, POST, PUT, PATCH, DELETE
endpointURL
refers to where this request will be made to
Parameter
Value
name
name of the header
isEncrypted
whether the header is encrypted
headerValue
the header's value
Cinchy v5.5 added an Authorization header type for REST API data syncs in Connections. An authorization request header can be used to provide credentials that authenticate a user with a server, allowing access to a protected resource. Selecting this header defines the Header Value as a password field.
If a post request is to be made, this is the body of the request
Parameter
Value
TYPE
This value has two choices:
OFFSET - has a limit key, limit, offset key and initial offset
CURSOR - has the new page URL JSONPath and a Cursor Key
HTTP Method can be chosen as GET, POST, PUT, PATCH, DELETE and the Endpoint URL refers to where this request will be made to. Since this is an insert specification, it will be inserted at the Endpoint URL.
Three sections can be added, Request Headers, POST Body and Variables to Extract.
While the first two sections are the same as REST API Source above, the Variables to Extract section has the following parameters:
name
name of the variable
pathInResponse
what the path is to this variable
HTTP Method can be chosen as GET, POST, PUT, PATCH, DELETE and the Endpoint URL refers to where this request will be made to. Since this is an update specification, it will be updated at the Endpoint URL.
The three sections which can be added are the same as as the Insert Specification.
HTTP Method can be chosen as GET, POST, PUT, PATCH, DELETE and the Endpoint URL refers to where this request will be made to. Since this is a delete specification, it will be deleted at the Endpoint URL.
The three sections which can be added are the same as as the Insert Specification.
Cinchy v5.5 introduced the Retry Configuration for REST API targets. This will automatically retry HTTP Requests on failure based on a defined set of conditions. A single retry configuration is defined for the REST API target, and applies to all requests configured in the Insert, Update, and Delete specifications. This capability 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 configuration:
Under the REST API destination tab, select API Specification > Retry Configuration
2. 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.
4. 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 is not 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}, e.g. "Content-Type=application/json".
Cinchy v5.5 introduced the ability to pass parameters from a REST response into post sync scripts during both real-time and batch data syncs, allowing you to do more with your REST API data.
In this example, we will be doing a batch data sync using the Cinchy Table [Product].[Names Test]. In this scenario we will be using the following simple API as our target: https://cinchy.net/API/Product/LatestCinchyReleaseDate
When we run our batch job, it will check for updates in our source table. These updates will trigger our REST API to fetch our defined value, which we can use in a post-sync script. In this case, our script will insert this value into a second table, [Product].[Response Table].
The following steps will walk you through how to utilize this functionality.
Set up your data sync to a REST API as normal. You can review our Source (Image 1), Destination (Image 2), and Sync Behaviour (Image 3) below.
2. Under the Post Sync tab, we want to input the CQL that, in our case, will take the defined variable from our REST API and insert it into the [Product].[Response Test] table (Image 4).
3. Add in your Permissions and click Save.
4. Once we have finished configuring our sync, we can run the job. It will check for new data in our Name column on our [Product].[Names] table (Image 5). When found, it will trigger the REST API to GET our “value” variable. Our post sync script will then take that value and INSERT it into the [Product].[Response Test] table (Image 6).