API Check Commands, Variables and Validators

API Check Steps are broken down into three categories: Commands, Variables, andValidators. Commands (color-coded blue) act as tasks to complete or (more broadly) steps for your API Check; Variables (color-coded purple) set a variable from a response that can be used in a subsequent step; Validations (color-coded green) verify elements that should be present before registering a failure.  

Table of Contents:

Commands

Variables

Validations

Commands

Back to Top

mceclip0.png

Here are the commands used in an API check. 

GET URL

Back to Top

Load a URL using HTTP GET.Using this step, an API check can be used as an advanced HTTP check, where you GET URL in one step, then Validate with HTTP Status Code Indicates Success. Repeat as often as needed. 

POST to URL

Back to Top

Send data to a URL using HTTP POST.

PUT to URL 

Back to Top

Send data to a URL using HTTP PUT.

PATCH to URL

Back to Top

Send data to a URL using HTTP PATCH.

DELETE URL

Back to Top

Load a URL using HTTP DELETE.

Variables

Back to Top

mceclip1.png

Set a variable from the response that can be used in a subsequent step. To use a variable in any subsequent step (in HTTP headers or data), enclose the variable name in dollar signs ($), for example:

HTTP Header: Authorization: Bearer $TOKEN$

JSON Data: {"authtoken": "$TOKEN$"}

XML Data: <authtoken>$TOKEN$</authtoken>

Set Variable name from current date and time

Back to Top

Name your variable, then specify a timezone location, any offset from that location’s timezone (specified in seconds), and the time format. For example, if you wanted to use a timestamp from 3 minutes ago you would use -180, or simply 180 for a timestamp 3 minutes into the future. To render the date (year and month) and time, use a format like the following:

%Y-%m-%d %H:%M:%S. 

Set variable name to a random value from a list

Back to Top

Name your variable, then list any variants that should be included in a comma separated list of values. For example, to have a check that will randomly assign values aaa, bbb, or ccc, list the variants as follows:

 aaa,bbb,ccc 

You can use this type of variable to check that a response contains one of multiple possible unique values. There are a number of use cases for this action, such as appending a random value from the list to a string or verifying the response was properly received.  

Set variable name to a random value from a range

Back to Top

Name your variable, then list the left and right margins for a range. The value assigned to the variable will come from this range of numbers, including the leftmost or rightmost margin of the range. A range from 0 to 100 will include 0, 100, and each possible number in between those two margins.

Set variable name to a literal value

Back to Top

Name your variable, then define a value. Variables can be called within other steps, including other variables, to form complex strings. For example, you can define one literal value (CONST1) and then assign it as part of another constant literal value (CONST2). Using this technique, you can send a token like:

CONST1 = MYTOKENVALUE

CONST2 = “Authorization: Bearer $CONST1$” 

Set variable name from response body or response header

Back to Top

Name your variable, then define the selector that contains the response you need. For example:

authorization.token[0]

This variable type can use regular expressions, matched fully or as a submatch from a larger group (useful for overly lengthy responses). This variable type allows regex. 

Validations

Back to Top

mceclip2.png

Here are validators you can use in an API check. 

HTTP Status Code Should Be Status

Back to Top

Check that the HTTP status code matches the specified status (eg. 200 or 404).

HTTP Status Code Indicates Success

Back to Top

Check that the HTTP status code indicates success (200-299).

HTTP Header Should/Should Not Contain Text/Regex

Back to Top

Check that the HTTP header matches or does not match the specified text or regex. 

For example, to retrieve a header Server from this endpoint, we format as follows:

header-matches-value.png

We can also use regex for complex string matching, such as this example looking for a 56 character alphanumeric string that also contains punctuation:

header-matches-regex.png

Response Should/Should Not Contain Text

Back to Top

Check that the response contains or does not contain the given text.

Response Should/Should Not Match Regex

Back to Top

Check that the response matches or does not match the given regex.

Selector Value from Response Does/Does Not Match Value

Back to Top

Check that the selected value in the response does or does not match the given value. Note: it is possible to use variables set previously as a form of validation. 

Use the following formats to specify selector:

For JSON responses: JSONPath or dot format, e.g. result.tokens[0].access_token

For XML responses: XPath, e.g. /result/token[1]/@access_token

Selector Value from Response Does/Does Not Match Regex

Back to Top

Check that the selected value in the response does or does not match the given regex.

Use the following formats to specify selector:

For JSON responses: JSONPath or dot format, e.g. result.tokens[0].access_token

For XML responses: XPath, e.g. /result/token[1]/@access_token

Numeric Value Selector Condition Value

Back to Top

Check that a numeric value from the response is equal to/greater than/etc. a value or variable.

numeric-selector.gif

Was this article helpful?
0 out of 0 found this helpful