# API Validation  
source: https://developer.mastercard.com/mastercard-gateway/documentation/testing/api-validation/index.md

The Gateway API performs these validations for each request field:

* **Mandatory field validation** -- If a field is required, it must be present in the request.
* **Data type validation** -- The field value must match the expected data type. For example, `Boolean`, `String`, `Integer`, or other supported types.
* **Character validation** -- Where applicable, the field must comply with the allowed character set, including any restrictions on special characters.
* **Length validation** -- The field value must meet the defined minimum and maximum length requirements.

If any validation check fails, the API returns an error response indicating the validation failure and the affected field.

|                                          Scenario                                           | result |   error.cause   |  error.validationType   |                error.field                 |                                                                      error.validation                                                                      |
|---------------------------------------------------------------------------------------------|--------|-----------------|-------------------------|--------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| The value provided in a field is not valid. For example, invalid field type or field length | ERROR  | INVALID_REQUEST | INVALID                 | `<field name for which validation failed>` | `<Text specific for the validation error, generated by the API according to a specific pattern. For example, including the field name and value provided>` |
| Mandatory field is missing                                                                  | ERROR  | INVALID_REQUEST | - MISSING - UNSUPPORTED | `<field name for which validation failed>` | `<Text specific for the field, generated by the API. For example, including the field name for the missing field>`                                         |

## Maximum length of API requests {#maximum-length-of-api-requests}

The maximum allowed size of the API request body can be configured to a maximum of 20,000 characters:

Where the API request body exceeds the configured number of characters, the API returns this error response:

```json
{
    "error": {
        "cause": "INVALID_REQUEST",
        "explanation": "Body has more than 20000 characters."
    },
    "result": "ERROR"
}
```

## API request limit {#api-request-limit}

The API has a 40,000 character limit for the size of a request.

If an API request exceeds this limit, the merchant receives a response with:

* result = ERROR
* error.explanation = Body has more than 40,000 characters.
