# Code and Formats
source: https://developer.mastercard.com/token-requestor-identifier-api/documentation/code-and-formats/index.md

## Error Messages {#error-messages}

The error message returned will depend on which API generated the error and at what point the request failed. Error messages will be in one of two formats:

* [API Error Messages](https://developer.mastercard.com/token-requestor-identifier-api/documentation/code-and-formats/index.md#api-error-messages) - returned from the API and typically occurs for incorrect input errors.
* [Gateway Error Messages](https://developer.mastercard.com/token-requestor-identifier-api/documentation/code-and-formats/index.md#gateway-error-messages) - returned from the gateway and typically occurs when OAUTH authentication fails.

## API Error Reason Codes {#api-error-reason-codes}

A HTTP response code of 200 will be returned if the call was successfully received and processed by the API.

|         Reason Code         | HTTP Status Code |                                                           Description                                                            |                  API                   |                                                                                     Resolution Tips                                                                                      |
|-----------------------------|------------------|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| INVALID_JSON                | 400              | Invalid JSON. The JSON could not be parsed.                                                                                      | Batch Request/Update Token Requestors. | Provide a valid JSON file format.                                                                                                                                                        |
| AUTHORIZATION_FAILED        | 401              | Authorization Failed. The ClientId and CustomerId validation was unsuccessful.                                                   | Batch Request/Update Token Requestors  | Provide the correct ClientId and CustomerId for validation.                                                                                                                              |
| INVALID_FIELD_FORMAT        | 400              | Invalid Field Format - {fieldName}. The field is not in the correct format. For instance, it should be a number but is a string. | Batch Request/Update Token Requestors  | Provide a valid field format in the request.                                                                                                                                             |
| INVALID_FIELD_LENGTH        | 400              | Invalid Field Length - {fieldName}. The value does not fall between the minimum and maximum length for the field.                | Batch Request/Update Token Requestors  | Provide the correct number of characters required in a field.                                                                                                                            |
| INVALID_FIELD_VALUE         | 400              | Invalid Field Value - {fieldName}. The value is not allowed for the field.                                                       | Batch Request/Update Token Requestors  | Provide a valid value in the request.                                                                                                                                                    |
| MISSING_REQUIRED_FIELD      | 400              | Missing Required Field - {fieldName}.                                                                                            | Batch Request/Update Token Requestors  | Provide the mandatory fields in the request.                                                                                                                                             |
| DUPLICATE_FIELD_VALUE       | 400              | Duplicate Field Value - {fieldName}. The value in the request that should be unique has been duplicated. e.g. entityId           | Batch Request/Update Token Requestors  | Remove the duplicate value from the request.                                                                                                                                             |
| INTERNAL_SERVICE_FAILURE    | 500              | The system had an internal exception.                                                                                            | Batch Request/Update Token Requestors  | Please retry after sometime, if the error persists, contact the MDES support team.                                                                                                       |
| INVALID_ARRAY_SIZE          | 400              | The array size is not valid -- {fieldName}. The array size is not within the allowed boundaries.                                 | Batch Request/Update Token Requestors  | Please limit the passing data as per the field description in the [API reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md). |
| CONSUMER_FACING_NAME_EXISTS | -                | The consumer facing entity name already exists.                                                                                  | Batch Response                         | Provide a unique name for consumer facing entity.                                                                                                                                        |
| INVALID_TRID                | -                | Invalid Token Requestor ID. The token requestor ID is invalid. It may not exist or may not be authorized.                        | Update Token Requestors                | Provide a valid token requestor ID.                                                                                                                                                      |

## Gateway Error Messages {#gateway-error-messages}

All the errors that the gateway returns follow the same data format:

```json
{
  "Errors": {
    "Error": [
      {
        "Source": "Gateway",
        "ReasonCode": "<Unique code>",
        "Description": "<Description of the error>",
        "Recoverable": true/false,
        "Details": null
      }
    ]
  }
}
```

Note: For more information on gateway error messages including the error codes, please refer to [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/security-and-authentication/gateway-error-codes/)

## API Error Messages {#api-error-messages}

A HTTP response code of 200 will be returned if the call is successfully received and accepted for processing. Errors during request validation of Batch Request/Update Token Requestors will be returned in the response in the following format:

#### Invalid Field Format {#invalid-field-format}

The API request contains data in a field which is incorrectly formatted.

**HTTP status code**   

`400`

```json
{
  "responseId": "0cc3e0fb-8d7d-4b57-8338-a3911aba4c1f",
  "errors": [
    {
      "source": "INPUT",
      "description": "Invalid Field Format - requestId",
      "reasonCode": "INVALID_FIELD_FORMAT",
    }
  ]
}
```

**Resolution**   

The description will contain details of which field has been formatted incorrectly. Correct the data in the field in accordance with the [API Reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md)

#### Invalid Field Length {#invalid-field-length}

The API request contains data in a field which exceeds the maximum length permitted.

**HTTP status code**   

`400`

```json
{
  "responseId": "0cc3e0fb-8d7d-4b57-8338-a3911aba4c1f",
  "errors": [
    {
      "source": "INPUT",
      "description": "Invalid Field Length - requestId",
      "reasonCode": "INVALID_FIELD_LENGTH",
    }
  ]
}
```

**Resolution**   

The description will contain details of which field has exceeded its maximum length. Correct the data in the field in accordance with the [API Reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md)

#### Invalid Field Value {#invalid-field-value}

The API request contains data in a field which has incorrect value.

**HTTP status code**   

`400`

```json
{
  "responseId": "0cc3e0fb-8d7d-4b57-8338-a3911aba4c1f",
  "errors": [
    {
      "source": "INPUT",
      "description": "Invalid Field Value - requestId",
      "reasonCode": "INVALID_FIELD_VALUE",
    }
  ]
}
```

**Resolution**   

The description will contain details of which field has the wrong value. Correct the data in the field in accordance with the [API Reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md)

#### Missing Required Field {#missing-required-field}

A mandatory field is not present in the API request.

**HTTP status code**   

`400`

```json
{
  "responseId": "123456",
  "errors": [
    {
      "entityId": "gggyh27e5A629dA11e3A949aA0800200yyy9ikjj",
      "source": "INPUT",
      "reasonCode": "MISSING_REQUIRED_FIELD",
      "description": "Missing Required Field - entityId"
    }
  ]
}
```

**Resolution**   

The description will contain details of which field is missing. Add the field in the request in accordance with the [API Reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md)

#### Invalid Array Size {#invalid-array-size}

The size of an array in the API request is not acceptable.

**HTTP status code**   

`400`

```json
{
  "responseId": "123456",
  "errors": [
    {
      "entityId": "gggyh27e5A629dA11e3A949aA0800200yyy9ikjj",
      "source": "INPUT",
      "reasonCode": "INVALID_ARRAY_SIZE",
      "description": "The array size is not valid - tokenRequestors"
    }
  ]
}
```

**Resolution**   

The description will identify the array of wrong size. Correct the size of the request in accordance with the [API Reference](https://developer.mastercard.com/token-requestor-identifier-api/documentation/api-reference/index.md)

### Batch Token Requestors Request Response {#batch-token-requestors-request-response}

The errors that subsequently occur during processing are returned in the request payload of asynchronous notification as below:

Batch Request Token Requestors

`POST`

```json
{ 
   "requestId":"123456", 
   "tokenRequestors":[ 
      { 
        "tokenRequestor": { 
        "entityId":"739d27e5629d-11e3949a0800200c9a66", 
        "tokenRequestorId": "98765432101" 
        } 
      }, 
      { 
        "tokenRequestor": { 
        "entityId":"dbc55444496a4896b41c5d5e2dd431e2" 
         }, 
         "error" :  { 
            "source" : "INPUT", 
            "reasonCode" : "CONSUMER_FACING_NAME_EXISTS", 
            "description" : " The consumer facing entity name already exists." 
         }         
      }
   ] 
} 
```

Batch Update Token Requestors

`POST`

```json
{ 
   "requestId":"123456", 
   "tokenRequestors":[ 
      { 
        "tokenRequestor": { 
        "tokenRequestorId":"12345678902" 
         }, 
         "error" :  { 
            "source" : "INPUT", 
             "reasonCode" : "INVALID_TRID", 
             "description" : "The token requestor id is invalid. It may not exist or may not be authorized." 
          }         
       } 
   ] 
} 
```

