# Code and Formats
source: https://developer.mastercard.com/small-business-credit-analytics/documentation/code-and-formats/index.md

## Error Handling {#error-handling}

Small Business Credit Analytics API uses standard HTTP response codes for success and failure notifications. The errors are further classified by error type as follows:

* 200 code corresponds to success
* 40X codes for a developer or user-related failures
* 50X codes for Mastercard related issues

## Gateway Error Codes {#gateway-error-codes}

Apart from the error codes returned by the Small Business Credit Analytics API, error codes can be returned by the Mastercard gateway, which verifies your request's signature and routes to the correct location.

For further information about 4xx/5xx response codes returned by the gateway and their possible resolutions, see [Gateway Error Codes](https://developer.mastercard.com/platform/documentation/security-and-authentication/gateway-error-codes/)

## Error Structure {#error-structure}

To ensure a consistent experience across all Mastercard APIs, the following structure is followed by the Small Business Credit Analytics for each error scenario that can occur.

**Single Error: country_code**

```json

{
  "Errors": {
    "Error": [
      {
        "Source": "CreditAnalytics",
        "ReasonCode": "INVALID_DATA: country_code",
        "Description": "Validation failed for country_code parameter",
        "Recoverable": false,
        "Details": "An invalid value was provided in for country_code. country_code must match ^[A-Z]+ and be a 3-letter country abbreviation, following the ISO Country Codes standard. Only currently supported countries are accepted."
      }
    ]
  }
}
```

**Matches Single Error: id_type**

```json

{
  "Errors": {
    "Error": [
      {
        "Source": "CreditAnalytics",
        "ReasonCode": "INVALID_DATA: id_type",
        "Description": "Validation failed for id_type parameter",
        "Recoverable": false,
        "Details": "An invalid value was entered for id_type. Currently SBCA supports only MERCHANT_ID"
      }
    ]
  }
}
```

**Metrics Single Error: location_id**

```json

{
  "Errors": {
    "Error": [
      {
        "Source": "CreditAnalytics",
        "ReasonCode": "INVALID_DATA: location_id",
        "Description": "Validation failed for location_id parameter",
        "Recoverable": false,
        "Details": "An invalid value was entered for location_id - Location ID should follow the following format '123e4567-e89b-12d3-a456-426614174000'."
      }
    ]
  }
}
```

| Field           | Description                                                                                                                                                                                                                                                                                                                                                   |
|:----------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Source**      | The application that generated this error. Every error message that is generated and returned by the Gateway will have this field equal to Gateway. If the field value is `CreditAnalytics`, then the error is generated by the Small Business Credit Analytics (SBCA) application.                                                                           |
| **ReasonCode**  | A unique constant identifying the error case encountered when Small Business Credit Analytics (SBCA) API is called. For example, `INVALID_DATA:has_consent` is used when the request is invalid due to some missing or invalid parameters.                                                                                                                    |
| **Description** | Description of the `ReasonCode` field with additional details.                                                                                                                                                                                                                                                                                                |
| **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 request parameter, retrying will never result in success. However, if the error is related to some unexpected timeout with the service, retrying the call could result in a successful response. |
| **Details**     | Provide detailed error information wherever appropriate to help in resolving errors.                                                                                                                                                                                                                                                                          |

## Small Business Credit Analytics API Errors {#small-business-credit-analytics-api-errors}

| Response Code | Reason Code                           | Description                                                                                              | Tip to Resolve                                                                                                                                                                              |
|:--------------|:--------------------------------------|:---------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 400           | INVALID_OATH_CONSUMER_KEY             | Consumer key must be 97 characters long, split by an exclamation mark symbol. Received: `length`         | Pass the valid OAuth consumer key.                                                                                                                                                          |
| 400           | QUERYSTRING.\<url_parameter\>.MISSING | The \<url_parameter\> `querystring` parameter is required but not provided                               | Pass the missing parameter.                                                                                                                                                                 |
| 400           | INVALID_DATA:\<url_parameter\>        | Validation failed for \<url_parameter\>                                                                  | Pass a valid value to the specified parameter. Check the details field for the exact validation failure.                                                                                    |
| 401           | DECLINED                              | Indicates that authentication has failed.                                                                | Consult the OAuth 1.0a documentation and double check the provided credentials for authentication.                                                                                          |
| 403           | CONSENT_NOT_PROVIDED                  | has_consent parameter was set to 'false'                                                                 | Consent from the merchant is required in order to access performance metrics for said merchant.                                                                                             |
| 403           | COUNTRY_NOT_PERMITTED                 | No Permission to access merchant information for the requested country_code.                             | Access to merchant data for this country is not permitted under your current agreement. To request access, please contact your Mastercard representative.                                   |
| 403           | COUNTRY_NOT_PERMITTED                 | No Permission to access merchant information for the requested location_id.                              | Access to merchant data for this location_id is not permitted under your current agreement. To request access, please contact your Mastercard representative.                               |
| 403           | ACCESS_FORBIDDEN                      | No permission to access Retail Sales Benchmarks                                                          | Ensure that you have permission for Retail Sales Benchmarks.                                                                                                                                |
| 403           | USER_NOT_FOUND                        | Unable to identify the user                                                                              | Please contact Mastercard representative to verify access.                                                                                                                                  |
| 403           | AGG_MERCHANT_NOT_PERMITTED            | No permission to retrieve the match for the aggregated merchant                                          | Merchant you are trying to search for is an aggregated merchant. SBCA only works with small and medium businesses. Please provide the non-aggregated merchant data to receive a match.      |
| 404           | MATCHES_NOT_FOUND                     | No potential matches found                                                                               | Check with the merchant for alternative values for the company name, address, and other similar values.                                                                                     |
| 404           | METRICS_NOT_FOUND                     | No potential metrics found for the provided merchant information                                         | Try calling the metrics API again in a few days in case this is resolved by Mastercard's ongoing reconciliation processes or processing additional transactions for this merchant.          |
| 404           | LOCATION_NOT_FOUND                    | No matched merchant found                                                                                | Often this is due to Mastercard ongoing reconciliation processes - try calling the matches API again with the original merchant details to get a new location ID.                           |
| 500           | INTERNAL_SERVER_ERROR                 | An unexpected error occurred in the application. Reach out to the Mastercard support with any questions. | Retry the request in a few minutes or reach out for help from our [support page](https://developer.mastercard.com/small-business-credit-analytics/documentation/support/index.md#get-help). |

