# Code and Formats
source: https://developer.mastercard.com/payment-account-reference-inquiry/documentation/code-and-formats/error-codes/index.md

## Return Codes {#return-codes}

All APIs return an HTTP response code of 200 if the call was successfully received and accepted for processing by the service.

Any errors that subsequently occur during processing are returned in the response payload. The error message format 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 depending on the type of error.

1. Application Error Messages - returned from the service application and typically occur for incorrect input or cryptography errors.
2. [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/security-and-authentication/gateway-error-codes/) - returned from the gateway and typically occur when OAUTH authentication fails.

Alert: To ensure forward-compatibility, client implementations must be resilient to new elements being added to the API responses in the future.

## Application Errors {#application-errors}

|             Reason Code             |             Description              |                                            Detail                                            |
|-------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------|
| INVALID_JSON                        | Invalid JSON                         | The JSON could not be parsed.                                                                |
| AUTHORIZATION_FAILED                | Authorization failed.                | The request failed to present a valid cert to access the API.                                |
| INVALID_FIELD_FORMAT                | Invalid Field Format - {fieldName}   | The field is not in the correct format. For instance, it should be a number but is a string. |
| INVALID_FIELD_LENGTH                | Invalid Field Length - {fieldName}   | The value does not fall between the minimum and maximum length for the field.                |
| INVALID_FIELD_VALUE                 | Invalid Field Value - {fieldName}    | The value is not allowed for the field.                                                      |
| MISSING_REQUIRED_FIELD              | Missing Required Field - {fieldName} | A required field is missing.                                                                 |
| CRYPTOGRAPHY_ERROR                  | Cryptography Error                   | There was an error decrypting the encrypted payload.                                         |
| INTERNAL_SERVICE_FAILURE            | Internal Service Failure             | Payment Account API had an internal exception.                                               |
| PAYMENT_ACCOUNT_REFERENCE_NOT_FOUND | No PAR Found                         | No PAR has been found for the supplied PAN or Token                                          |

### General Application Error format {#general-application-error-format}

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

#### HTTP status code {#http-status-code}

`200`

```json
{
  "responseId": "<unique response id>",
  "errors": [
    {
      "source": "INPUT",
      "description": "<error description>",
      "reasonCode": "<reason code or description>",
      "recoverable": true/false
    }
  ]
}
```

Field explanations:

* **source** - the application that generated this error. Every error message that is generated and returned by the application will have this field equal to `INPUT`. When the value of the source field is something else, it means the error was generated elsewhere.
* **reasonCode** - a unique constant identifying the error case encountered during transaction processing.
* **recoverable** - Indicates whether this error will always be returned for this request, or retrying could change the outcome. For example, if the request contains an invalid signature, retrying will never result in a success. However, if the error is related to some unexpected timeout with the service, retrying the call could result in a successful response.

### Authorization Failed {#authorization-failed}

Returned if the Client ID has not been enabled for the Payment Account Inquiry Service.

**HTTP status code**   

`200`

```json
{
  "responseId": "111111",
  "errors": [
    {
      "source": "INPUT",
      "description": "Authorization Failed",
      "reasonCode": "AUTHORIZATION_FAILED",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

Contact your Mastercard CIS implementation manager to ensure all the necessary on-boarding steps have been completed.

### Cryptography Error {#cryptography-error}

A cryptography error will occur when the payload has not been encrypted correctly.

**HTTP status code**   

`200`

```json
{
  "responseId": "111111",
  "errors": [
    {
      "source": "INPUT",
      "description": "Cryptography Error",
      "reasonCode": "CRYPTOGRAPHY_ERROR",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

A cryptography error could be generated for a number of reasons. Typically this error occurs when the service has been unable to decrypt the payload supplied in the API request. Check the correct keys are being used as separate encryption keys are required for MTF and Production. Please also refer to the API reference for [guidance on encryption](https://developer.mastercard.com/payment-account-reference-inquiry/documentation/api-reference/index.md#encrypt-decrypt-configuration)

### Payment Account Reference Not Found {#payment-account-reference-not-found}

Returned if no PAR has been found for the supplied PAN or Token

**HTTP status code**   

`200`

```json
{
  "responseId": "111111",
  "errors": [
    {
      "source": "INPUT",
      "description": "Payment Account Reference Not Found",
      "reasonCode": "PAYMENT_ACCOUNT_REFERENCE_NOT_FOUND",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

PAR is not available for the PAN or token supplied in the request. Please refer to the [Overview](https://developer.mastercard.com/payment-account-reference-inquiry/documentation/index.md) section for details of the Mastercard product ranges on which PAR values are assigned.

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

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

**HTTP status code**   

`200`

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

**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/payment-account-reference-inquiry/documentation/api-reference/index.md)

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

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

**HTTP status code**   

`200`

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

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

The value is not allowed for the field.

**HTTP status code**   

`200`

```json
{
  "responseId": "123456",
  "errors": [
    {
      "source": "INPUT",
      "description": "Invalid Field Value - oaepHashingAlgorithm",
      "reasonCode": "INVALID_FIELD_VALUE",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

The description will contain details of the field that contains the incorrect value. Correct the data in the field in accordance with the [API Reference](https://developer.mastercard.com/payment-account-reference-inquiry/documentation/api-reference/index.md)

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

The API request is missing a required mandatory field.

**HTTP status code**   

`200`

```json
{
  "responseId": "1debc552-833f-4bcb-bd3a-5f675a9102a5",
  "errors": [
    {
      "source": "INPUT",
      "description": "Missing Required Field - requestId",
      "reasonCode": "MISSING_REQUIRED_FIELD",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

Correct the request to contain all mandatory field as described in the [API Reference](https://developer.mastercard.com/payment-account-reference-inquiry/documentation/api-reference/index.md)

### Authorization Failed {#authorization-failed-1}

Returned if the Client ID has not been enabled for the Payment Account Inquiry Service.

**HTTP status code**   

`200`

```json
{
  "responseId": "111111",
  "errors": [
    {
      "source": "INPUT",
      "description": "Authorization Failed",
      "reasonCode": "AUTHORIZATION_FAILED",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

Contact your Mastercard CIS implementation manager to ensure all the necessary on-boarding steps have been completed.

### Invalid JSON {#invalid-json}

The JSON request is incorrectly formatted.

**HTTP status code**   

`200`

```json
{
  "responseId": "73245138-f976-41ec-8b72-ecde27a503aa",
  "errors": [
    {
      "source": "INPUT",
      "description": "Invalid JSON",
      "reasonCode": "INVALID_JSON",
      "recoverable": false
    }
  ]
}
```

**Resolution**   

Check the message is a correctly formatted JSON and resubmit.

## Gateway Errors {#gateway-errors}

Refer to [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/gateway-error-codes/)
