# Creating a bank account

> Creating a bank account using Qualy's API.

Qualy is capabable to automatically payout [Partnerships](https://v1-spec.qualyhq.com/#post-/v1/partnerships/create) automatically. A bank account--amongst other things such as legal information, address, and partnership's contacts--is necessary. Different countries and currencies have different requirements, this guides walks you through adding a bank account.

---

## Before you start

If you are creating a bank account for a specific Partnershio, you will need to have the Partnership's `_id` to create the Bank account, check our [Partnership's API Reference](https://v1-spec.qualyhq.com/#post-/v1/partnerships/create) to create a Partnership.

## Listing bank account requirements

Different **countries** and **currencies** may have different information requirements. Before creating the bank account, it's necessary to fetch the fields for the currency and country of the bank account. Use this GET endpoint to learn what datapoints are required to send a payment to your partnershop.

This this example, we are fetching the bank account requirements for the currency "AUD" and country "AU":

```javascript
try {
  const response = await fetch('https://api.qualyhq.com/v1/bank-accounts/requirements/AU/AUD', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'ApiKey your-api-key-here',
      'X-TENANT-ID': 'your-tenant-id-here',
    },
  });

  if (response.ok) {
    const data = await response.json();

    console.log(data);
  } else {
    throw new Error(`Request failed with status: ${response.status}`);
  }
} catch (error) {
  console.error(error);
}
```

The above `GET` request may return a response like the below:

```json
{
    "data": {
        "requirements": [
            {
                "type": "text",
                "name": "accountName",
                "validation": "required"
            },
            {
                "type": "text",
                "name": "bankName",
                "validation": "required",
                "requirementType": "australian"
            },
            {
                "requirementType": "australian",
                "validation": "required",
                "name": "holderType",
                "min": null,
                "max": null,
                "regexp": null,
                "type": "select",
                "options": [
                    {
                        "value": "personal"
                    },
                    {
                        "value": "business"
                    }
                ]
            },
            {
                "requirementType": "australian",
                "validation": "required",
                "name": "routingNumber",
                "min": 6,
                "max": 7,
                "regexp": "^\\d{3}\\-?\\d{3}$",
                "placeholder": "802985",
                "type": "text"
            },
            {
                "requirementType": "australian",
                "validation": "required",
                "name": "accountNumber",
                "min": 4,
                "max": 28,
                "regexp": "^\\d{4,9}$",
                "placeholder": "123456789",
                "type": "text"
            }
        ]
    },
    "hasMore": false,
    "count": 5
}
```

### Requirement types

Qualy organizes and groups the different requirements that may be necessary by `requirementTypes`. When creating a bank account you will need to supply this value.

| Requirement name | Description |
| --- | --- |
| `australian` | This requirement type is used for local Australian bank accounts. |
| `euro` | This requirement type is used for local European bank accounts. |
| `european` | This requirement type is used for local European bank accounts. |
| `colombia` | This requirement type is used for local Colombian bank accounts. |
| `brazil` | This requirement type is used for local Brazilian bank accounts. |
| `united-kingdom` | This requirement type is used for local United Kingdom bank accounts. |
| `new-zealand` | This requirement type is used for local New Zealand bank accounts. |
| `united-states` | This requirement type is used for local United States bank accounts. |
| `india` | This requirement type is used for local Indian bank accounts. |
| `pakistan` | This requirement type is used for local Pakistani bank accounts. |
| `swift_code` | This requirement type is used for SWIFT code bank accounts. |
| `turkey` | This requirement type is used for local Turkish bank accounts. |
| `thailand` | This requirement type is used for local Thai bank accounts. |
| `romania` | This requirement type is used for local Romanian bank accounts. |
| `argentina` | This requirement type is used for local Argentine bank accounts. |
| `mexico` | This requirement type is used for local Mexican bank accounts. |
| `china` | This requirement type is used for local Chinese bank accounts. |
| `canada` | This requirement type is used for local Canadian bank accounts. |

## Creating a bank account

Once you fetched the bank account requirements, and you now have the necessary information, you can create a bank account entity, calling the [Bank Accounts API](https://v1-spec.qualyhq.com/#post-/v1/bank-accounts/create).

```javascript
try {
  const response = await fetch('https://api.qualyhq.com/v1/bank-accounts/create', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'ApiKey your-api-key-here',
      'X-TENANT-ID': 'your-tenant-id-here',
    },
    body: JSON.stringify({
      "accountName": "Account name",
      "accountNumber": "12345678",
      "bankName": "Bank name",
      "country": "AU",
      "currency": "AUD",
      "holderType": "business",
      "requirementType": "australian",
      "routingNumber": "123456",
    }),
  });

  if (response.ok) {
    const data = await response.json();

    console.log(data);
  } else {
    throw new Error(`Request failed with status: ${response.status}`);
  }
} catch (error) {
  console.error(error);
}
```

### Creating a bank account for a partnership

You can create a bank account and associate to a partnership by providing the parthership `_id` using the property `partnership` when calling the [Bank Accounts API](https://v1-spec.qualyhq.com/#post-/v1/bank-accounts/create).

Here's an example:

```javascript
try {
  const response = await fetch('https://api.qualyhq.com/v1/bank-accounts/create', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'ApiKey your-api-key-here',
      'X-TENANT-ID': 'your-tenant-id-here',
    },
    body: JSON.stringify({
      "accountName": "Account name",
      "accountNumber": "12345678",
      "bankName": "Bank name",
      "country": "AU",
      "currency": "AUD",
      "holderType": "business",
      "partnership": "6608fa09ae372f75deb3c6ad",
      "requirementType": "australian",
      "routingNumber": "123456",
    }),
  });

  if (response.ok) {
    const data = await response.json();

    console.log(data);
  } else {
    throw new Error(`Request failed with status: ${response.status}`);
  }
} catch (error) {
  console.error(error);
}
```

## Things to know

Qualy has some rules, features and restrictons when creating a bank account, here's what you need to know:

* Only one Bank Account per currency is allowed.
* You may need to provide a `bankName`, but Qualy may overwrite it. Qualy fetches the `bankName` based on `accountNumber` and `routingNumber` for certain countries.
* Qualy may automatically add `address` property automatically. Qualy uses the `routingNumber` to fetch the address of the Bank Account's branch automatically. Only available for certain countries.

### Data masking

For security purposes, sensitive bank account fields are masked in most API responses. Fields such as account numbers, routing numbers, IBANs, and similar identifiers are returned with only the last 4 characters visible (e.g. `••••••5678`). This masking is applied consistently across all endpoints that return bank account data.
