> For the complete documentation index, see [llms.txt](https://docs.avoautomation.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avoautomation.com/avo-assure/actions/apis/assertion/status-code-2.md).

# Response body contains

This is a pre-built action available under **@Assertion** element type. This action validates whether the API response body contains the expected text or value or matches the expected regex pattern. The output variable stores the validation result as True or False.

{% hint style="info" %}
**Note**: An API request must be added and executed successfully before configuring or evaluating API Assertion.
{% endhint %}

## Syntax

**Input Value**: `<Text or value or regex pattern to search in response>;<Match type: Contains/Regex>`

| Argument                                                | Description                                                                                                                                                                                                                                                                                                            |
| ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \<Text or value or regex pattern to search in response> | Provide the text, value, or regular expression pattern that you want to search for in the API response body.                                                                                                                                                                                                           |
| \<Match type: Contains/Regex>                           | <p>Specify the matching method to use for validating the response body: </p><ul><li><strong>Contains</strong>: Searches for the specified text or value anywhere in the API response body.  </li><li><strong>Regex</strong>: Searches the API response body using the specified regular expression pattern. </li></ul> |

**Output Value**: `<Keyword Status (Optional)>`

| Argument                     | Description                                                                       |
| ---------------------------- | --------------------------------------------------------------------------------- |
| \<Keyword Status (Optional)> | The keyword status variable stores the assertion status as **True** or **False**. |

### Example 1: Validating Text in an API

In this example, we explain how to verify that the API response body contains the expected text.

* **Action**: Response body contains&#x20;
* **Input Value**: John;Contains&#x20;
  * The first value **John** specifies the text to search for in the API response body.&#x20;
  * The second value **Contains** specifies that the action searches for the text anywhere in the response body.&#x20;

```json
JSON Response Body
{
  "first_name": "John",
  "last_name": "Doe",
  "phone": "8765678987",
  "email": "johndoe@gmail.com.com",
  "id": 205
}
```

* **Output Value**: {Status}&#x20;
  * The output variable **{Status}** stores the verification result with the following possible values:&#x20;
    * **True**: If the expected text is found in the API response body.&#x20;
    * **False**: If the expected text is not found in the API response body.&#x20;
* **Logical Explanation**: The **Response body contains** action fetches the expected text **John** and match type **Contains** from the **Input Value** column. The action searches for the complete API response body for the specified text. **John** is present in the availability field, the **{Status}** variable stores **True**.

![](https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2FKhh0yM2nwM7uMgrsKpcM%2Funknown.png?alt=media\&token=da004319-e5c9-47ca-8858-c7a2e9cdfcc3)

### Example 2: Validating Response Body Using a Regex Pattern

In this example, we explain how to verify that the API response body contains a value that matches the specified regular expression pattern.

{% hint style="info" %}
**Note**: To validate the response body using a regular expression, the response body must contain a value that matches the specified regex pattern.
{% endhint %}

* **Action**: Response body contains
* **Input Value**: ^\[A-Za-z0-9]+$;Regex
  * The first value **^\[A-Za-z0-9]+$** specifies the regular expression pattern to validate an alphanumeric value containing only letters and numbers.
  * The second value **Regex** specifies that the action uses regular expression matching to validate the response body.

```json
JSON Response Body
{
  "customerId": "CUST12345",
  "referenceCode": "ABC12345",
  "status": "Active"
}
```

* **Output Value**: {Status}
  * The output variable **{Status}** stores the verification result with the following possible values:
    * **True**: If the API response body contains a value that matches the specified regular expression pattern.
    * **False**: If the API response body does not contain a value that matches the specified regular expression pattern.
* **Logical Explanation**: The **Response body contains** action fetches the regular expression pattern **^\[A-Za-z0-9]+$** and match type **Regex** from the **Input Value** column. The action searches the response body for a value that contains only letters and numbers. If the response body matches the regex pattern, the **{keyword\_status}** variable stores **True.**

![](https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2FpT1XAJqBLNGPGRoKowcx%2Funknown.png?alt=media\&token=d16bd35f-a460-43b7-aacf-f6550b8df7b0)

**Following are some common use cases of regex patterns:**

| Use Case                                 | Regex Pattern                                                                                     | Example Value                               |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| Contains only digits                     | ^\d+$                                                                                             | 12345                                       |
| Exactly 6 digits (ZIP/PIN)               | ^\d{6}$                                                                                           | 560001                                      |
| Exactly 10 digits (Phone)                | ^\d{10}$                                                                                          | 9876543210                                  |
| Positive integer                         | ^\[1-9]\d\*$                                                                                      | 125                                         |
| Decimal number                           | ^\d+(\\.\d+)?$                                                                                    | 10.5                                        |
| Alphabetic characters only               | ^\[A-Za-z]+$                                                                                      | John                                        |
| Alphabets with spaces                    | ^\[A-Za-z ]+$                                                                                     | John Doe                                    |
| Alphanumeric                             | ^\[A-Za-z0-9]+$                                                                                   | EMP123                                      |
| Email address                            | ^\[A-Za-z0-9.\_%+-]+@\[A-Za-z0-9.-]+\\.\[A-Za-z]{2,}$                                             | <john@test.com>                             |
| URL                                      | ^https?://.+                                                                                      | [https://example.com](https://example.com/) |
| UUID                                     | ^\[0-9a-fA-F]{8}-\[0-9a-fA-F]{4}-\[1-5]\[0-9a-fA-F]{3}-\[89abAB]\[0-9a-fA-F]{3}-\[0-9a-fA-F]{12}$ | 550e8400-e29b-41d4-a716-446655440000        |
| Date (YYYY-MM-DD)                        | ^\d{4}-\d{2}-\d{2}$                                                                               | 2026-07-24                                  |
| Time (HH:mm:ss)                          | ^\d{2}:\d{2}:\d{2}$                                                                               | 14:30:45                                    |
| DateTime (ISO 8601)                      | ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$                                                            | 2026-07-24T14:30:45Z                        |
| Starts with prefix                       | ^EMP.\*                                                                                           | EMP1023                                     |
| Ends with suffix                         | .\*\\.pdf$                                                                                        | report.pdf                                  |
| Contains specific text                   | .\*Success.\*                                                                                     | Operation Success                           |
| Boolean                                  | \`^(true                                                                                          | false)$\`                                   |
| Hexadecimal                              | ^\[0-9A-Fa-f]+$                                                                                   | A1B2C3                                      |
| Password (8+ chars, upper, lower, digit) | ^(?=.\*\[a-z])(?=.\*\[A-Z])(?=.\*\d).{8,}$                                                        | Test1234                                    |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.avoautomation.com/avo-assure/actions/apis/assertion/status-code-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
