# Creating accounts

## Prerequisites

- **Authentication scopes** — `accounts:admin`
For more information, refer to [Authentication scopes](/products/byol/concepts/api_concepts/authentication/authentication_oauth#list-of-authentication-scopes).


You must have

- [created a user](/products/byol/guides/users/users_onboarding_create).
- [created an account group](/products/byol/guides/accounts/accounts_create_account_groups).
- **Webhook handler ready** — Set up a webhook endpoint to listen for account lifecycle events.
  - Subscribe to [`ACCOUNT.*`](/products/byol/guides/accounts/accounts_webhooks) events.
For more information, refer to [Implementing webhooks](/products/byol/getting_started/implementing_webhooks).


After the creation of the account group, you can now setup an account with:

**POST** [`/accounts`](/api/accounts/create_account)

**Example**

Example request
```json
{
  "user_id": "413715f2-5401-4b97-8055-034a6b879f8c",
  "account_group_id": "fa2414ed-8d62-46fd-85ed-565a340c81d6",
  "type": "TRADING",
  "name": "Main account"
}
```

Example response
```json
{
  "id": "ad45b27f-c0e7-4cfb-b48c-a83670dbdfbd",
  "created_at": "2020-08-24T14:15:22Z",
  "updated_at": "2020-08-24T14:15:22Z",
  "account_group_id": "fa2414ed-8d62-46fd-85ed-565a340c81d6",
  "type": "TRADING",
  "users": [
    {
      "id": "9c36af78-91a0-4174-a515-fc81214e3dab",
      "type": "OWNER"
    }
  ],
  "account_number": 1,
  "name": "Main account",
  "status": "ACTIVE"
}
```

| Parameter | Description |
|  --- | --- |
| `user_id` | The ID of the user to be associated with this account. |
| `account_group_id` | The ID of the account group to be associated with this account. |
| `type` | Specify the type `TRADING` or `PORTFOLIO` for this account. |
| `name` | Optionally, you can provide a nickname for the account that can be used for reporting purposes. |


The account will be created with the `PENDING_APPROVAL` status and switches to `ACTIVE` as soon as the user onboarding process is completed.

Furthermore, you will receive a webhook with the respective [account created event](/api/accounts/account_event). As soon as all prerequisites for activating the account are passed, you also receive an [account activated event](/api/accounts/account_event).

Webhooks notify you of events in business processes, not the success or failure of the initialisation of those processes.

Please be sure to check the [HTTP status](/api_errors) of the response to your requests and handle failure cases appropriately.

## Account status

The following status apply to an account:

| Status | Description |
|  --- | --- |
| `PENDING_APPROVAL` | Account approval is pending - the account is visible via our API but cannot be acted on. |
| `ACTIVE` | Account is active. The parent account group has met its activation requirements, so the account can be funded and can accept orders. For more information, refer to [Role-based activation](/products/byol/guides/users/role_based_activation). |
| `LOCKED` | Account is locked for all actions. |
| `CLOSING` | Account is closing - only sell orders or the transfer of positions out are permissible before the account is closed. |
| `CLOSED` | Account is closed with zero balance successfully. |


**Recommended: Use webhooks to track account activation**

To check if the account is activated, set up a webhook listener for `ACCOUNT.ACTIVATED`. You'll receive automatic notification when the account transitions from `PENDING_APPROVAL` to `ACTIVE` and is ready for trading operations.

For more information, refer to [Account and account group webhooks](/products/byol/guides/accounts/accounts_webhooks)

## Listing accounts

You can list all accounts of a specific user with

- **GET**[`/users/{user_id}/accounts`](/api/accounts/list_user_accounts)


All accounts can be listed with

- **GET** [`/accounts`](/api/accounts/list_accounts)


## Next Steps

You are all set now: a user is onboarded and an account group as well as an account have been created. Your user is now ready to place the first order. Follow the [Orders guide](/products/byol/guides/orders/orders_introduction).