Assertions
Automatically validate API responses after execution with system-suggested, manual, and general assertions. Validate specific fields, array elements, headers, and overall response conditions such as status code, response time, and payload size.
Assertions help you validate the response of an API automatically after execution. Optraflow supports system-suggested, manual, and general assertions for validating response fields, array elements, headers, and overall response conditions.
Types of assertions
1. System-suggested assertions
Optraflow analyzes the API response and suggests relevant assertions based on the response structure and field types. Common suggestions include:
- Field Exists — verify that a field exists.
- Data Type — verify the expected data type.
- Equals Value — verify that a field matches a specific value.
- Contains — verify that a field or response contains a specific value or text.
2. Manual assertions
Add assertions manually for specific fields in the response. Available options depend on the field type — for example, for a numeric field such as amount, you can validate whether the value:
- Equals a value
- Is greater than a value
- Is less than a value
- Is not equal to a value
Array element assertions
You can validate a specific field across all objects in an array with a single assertion. For example:
{
"products": [
{ "name": "Product A", "amount": 250 },
{ "name": "Product B", "amount": 500 }
]
}You can add an assertion that amount should be greater than 0 for all products. Optraflow automatically validates the assertion against every element in the array — this is especially useful when an API returns hundreds of objects and the same field needs to be validated for every object.
3. General assertions
General assertions validate the overall API response rather than a specific field. Supported assertions include:
- Response Time — verify that the response is within the expected time.
- Payload Size — verify that the response size is within the expected limit.
- Status Code — verify the expected HTTP status code.
- Contains Text — verify that the response contains specific text.
- Contains Static Value — verify that the response contains a value used in the request.
- Contains Dynamic Value — verify that a dynamically generated value is returned correctly.
- Contains Extracted Variable — verify that a value extracted from a previous request is present in the response (Request Chain).
Header assertions
You can also add assertions for response headers. Choose the required header assertion based on your API requirements and risk level.
Assertion Manager
The Assertion Manager provides a centralized place to add, review, verify, and manage assertions for an API response. You can:
- Review system-suggested assertions.
- Add field-level assertions.
- Add array element assertions.
- Add response-level assertions.
- Add header assertions.
- Add assertions using a JSONPath.
- Verify assertions before saving.
- Manage previously saved assertions.
A quick execution result is shown when you verify the assertions, helping you confirm whether the configured validations work as expected.
Saved assertions
Once an assertion is saved, it is automatically validated whenever the API is executed in Request Builder. Saved assertions can also be reused in:
- Test Suite
- Request Chain
In a Request Chain, you can select an existing assertion or create a new one. Saved assertions are automatically validated every time the chain is executed. Saved assertions can be managed from:
Add an assertion
- 1
Execute the API
Execute the API in Request Builder.
- 2
Open Assertions
After receiving the response, open the Assertions option.
- 3
Choose the assertion type
Select field-level, array, response-level, or header assertion.
- 4
Configure the assertion
Configure the expected condition or value for the assertion.
- 5
Save the assertion
Save the assertion so it runs automatically on future executions.
- 6
Review with Assertion Manager
Use the Assertion Manager to review, verify, and manage saved assertions.
Example
API Request
↓
API Response
↓
Add Assertion
↓
Save
↓
Execute API
↓
Assertion Validation
↓
Pass / Fail