# Balance API (Compliant with Payment Services Directive for EU customers)
source: https://developer.mastercard.com/cross-border-services/documentation/api-ref/psd2-eu-balance-api/index.md

You can use this API to obtain account details including balances if enabled for prefunding settlement.

## API {#api}

[**Open Specification**](https://static.developer.mastercard.com/content/cross-border-services/swagger/cross-border-eu-swagger.yaml)

For further information on URL/ Input Parameter restrictions, please take a look at [API Conventions](https://developer.mastercard.com/cross-border-services/documentation/api-basics/api-conventions/index.md).

## Retrieve Accounts Balances {#retrieve-accounts-balances}

[**Open Specification**](https://static.developer.mastercard.com/content/cross-border-services/swagger/cross-border-eu-swagger.yaml)


API Reference: `GET /send/partners/{partner_id}/crossborder/accounts`

<br />

## Retrieve Account Balances by AccountId {#retrieve-account-balances-by-accountid}

[**Open Specification**](https://static.developer.mastercard.com/content/cross-border-services/swagger/cross-border-eu-swagger.yaml)


API Reference: `GET /send/partners/{partner_id}/crossborder/accounts/{account_id}`

<br />

* **Formats supported** : JSON   
* **HTTP Version**: 1.0/ 1.1
* **Required HTTP header parameters** :   
  content-type : Format of the inbound content being submitted. example: application/ json   
  content-length: Length of the inbound content body in octets.

## Endpoints {#endpoints}

Note: The Sandbox testing facility is not available for Balance API.

#### Retrieve Accounts Balance {#retrieve-accounts-balance}

* MTF URL: [https://mtf.api.xbs.mastercard.eu/send/partners/{partner_id}/crossborder/accounts](https://mtf.api.xbs.mastercard.eu/send/partners/%7Bpartner_id%7D/crossborder/accounts)
* Production URL: [https://api.xbs.mastercard.eu/send/partners/{partner_id}/crossborder/accounts](https://api.xbs.mastercard.eu/send/partners/%7Bpartner_id%7D/crossborder/accounts)

#### Retrieve Account Balance by AccountId {#retrieve-account-balance-by-accountid}

* MTF URL: [https://mtf.api.xbs.mastercard.eu/send/partners/{partner_id}/crossborder/accounts/{account_id}](https://mtf.api.xbs.mastercard.eu/send/partners/%7Bpartner_id%7D/crossborder/accounts/%7Baccount_id%7D)
* Production URL: [https://api.xbs.mastercard.eu/send/partners/{partner_id}/crossborder/accounts/{account_id}](https://api.xbs.mastercard.eu/send/partners/%7Bpartner_id%7D/crossborder/accounts/%7Baccount_id%7D)

## API Convention {#api-convention}

Take a look at the [API Conventions](https://developer.mastercard.com/cross-border-services/documentation/api-basics/api-conventions/index.md) for general guidelines.

## Payload Encryption {#payload-encryption}

All the request payload sent by you to Mastercard must be encrypted. And you will need to decrypt the payload sent by Mastercard.   

For more detailed information on payload **Encryption/ Decryption** , please see [here](https://developer.mastercard.com/cross-border-services/documentation/api-ref/encryption/index.md)

## Sandbox Testing {#sandbox-testing}

You can make API calls to the Sandbox server from your application code using the [tutorials](https://developer.mastercard.com/cross-border-services/documentation/tutorials/index.md), which involves creating a Mastercard Developers project and using the Sandbox keys to generate the required OAuth 1.0a Authorization Header.
Tip: During the onboarding process, Mastercard will assign a registered partner ID to test in the higher environments (MTF Test and Production). This partner ID will not be able to access the sandbox environment, but the customer can still access sandbox by using the non-registered partner ID.   
Any correctly formatted partner ID can be used in the sandbox. As a best practice, use the first 15 digits of your institution's name (alphanumeric and/or special characters, no spaces) as the Partner_ID.   
For testing in sandbox, please use unique transaction_reference on each run. Note: The sandbox does not return parameters unique to a specific Customer; such as pricing, limits, and corridor-specific data requirements, but allows you to test general call structure and responses outside of the production environment. After sandbox testing is completed, Customers meeting the eligibility requirements will be assigned a project manager to do integrated testing in the test environment that has been configured to include requested receiving corridors, current foreign exchange rates, and fixed and variable fees specific to the Customer.

### Test cases {#test-cases}

The Sandbox server returns simulated, static responses.

#### Retrieve all Active Accounts {#retrieve-all-active-accounts}

You can use the following test cases to produce specific responses.

| Status  |                                         Test Case                                         |                                 Action                                 |
|---------|-------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| Success | Retrieve all active Accounts return message "Returned response with all active accounts". | Send request to Balance API with include_balance=false in the request. |

#### Retrieve all Active Accounts Balances {#retrieve-all-active-accounts-balances}

You can use the following test cases to produce specific responses.

| Status  |                                             Test Case                                             |                                Action                                 |
|---------|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| Success | Retrieve reserved and available balances for all active accounts (queuedBalance is not included). | Send Request to Balance API with the include_balance=true in request. |

#### Retrieve Account Balances by Account Id {#retrieve-account-balances-by-account-id}

You can use the following test cases to produce specific responses.

|           Status            |                                                                                          Test Case                                                                                          |                                Action                                 |
|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| Success                     | Retrieve balances (other than queuedBalance) of Single Account by Account Id with balance included having return message "Returned response with active account number with all balances" . | Send request to Balance API with accountId.                           |
| Success for Prefund queuing | Retrieve balances of Single Account by Account Id with balance included having return message "Returned response with active account number with all balances including queuedBalance".     | Send request to Balance API with accountId acct_ssq                   |
| Rejected                    | Retrieve balances of Single Account by Account Id with Invalid Input value having return message "Rejected response Invalid Input Value with error code 082000".                            | Send request to Balance API with invalid accountId acct++@bc .        |
| Rejected                    | Retrieve balances of Single Account by Account Id with Invalid Input length having return message "Rejected response Invalid Input Length with error code 072000".                          | Send request to Balance API with input value more than 30 characters. |
| Rejected                    | Retrieve balances of Single Account by Error code having return message "Rejected response PROVIDER_NOT_ENABLED_PRE_FUND with error code 130192".                                           | Send request to Balance API with accountId ERR_130192.                |
| Rejected                    | Retrieve balances of Single Account by Error Code having return message "Rejected response SETTLEMENT_ACCOUNT_NOT_FOUND with error code 130193".                                            | Send request to Balance API with accountId ERR_130193.                |

