> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/charging_account_api.md).

# Charging Account API

TPOSS Charging Account API allows you to read and manage charging accounts using the following RPC methods:

- [Charging.Account.Create](#chargingaccountcreate) - to provision the new charging account
- [Charging.Account.Read](#chargingaccountread) - to fetch the charging account by the given charging account name
- [Charging.Account.Delete](#chargingaccountdelete) - to delete the charging account by the given charging account name
- [Charging.Account.Update](#chargingaccountupdate) - to update the charging account by the given charging account name

## Data model

A charging account is represented by an object with the following properties:

|Attribute | Type | Description
|---|---|---
| ChargingAccountId | string | Unique identifier for the charging account.
| TariffId | string | Unique identifier for the tariff associated with the charging account. For a more detailed description of the tariffs, see the [tariffs](https://docs.cennso.com/components/tposs/latest/configuration/charging.md#available-tariffs) documentation.
| ValidFrom | string | Validity range start date in the ISO 8601 format.
| ValidTill | string | Validity range end date in the ISO 8601 format.
| Balances | list | List of balances associated with the charging account. For more information, see [balance data model](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/balance_api.md#data-model).
| TariffOptions | object | Optional field which specifies tariff options for the given account. For more information, see the table below.

The tariff options are represented by an object with the following properties:

|Attribute | Type | Description
|---|---|---
| UnlimitedStreaming | bool | If set to `true`, the parameter enables unlimited streaming for the charging account.
| UnlimitedStreamingCarrierGroups | list | List of carrier groups names.

## API methods

### Charging.Account.Create

The method allows you to register a new charging account with the given account information.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
|---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| ChargingAccountId | string | required | Unique identifier for the charging account. |
| TariffId | string | required | Unique identifier for the tariff associated with the charging account. |
| ValidFrom | string | required | Validity range start date in the ISO 8601 format. |
| ValidTill | string | required | Validity range end date in the ISO 8601 format. |
| TariffOptions | object | optional | Tariff options. |

Example of the request:

```bash
curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": "1",
  "jsonrpc": "2.0",
  "method": "Charging.Account.Create",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "ChargingAccountId": "700030010@.account.charging.<tenant>",
    "TariffId": "online",
    "ValidFrom": "2015-03-01T18:12:00Z",
    "ValidTill": "2018-07-31T23:59:59Z",
    "TariffOptions": {
      "UnlimitedStreaming": true,
      "UnlimitedStreamingCarrierGroups": ["27@carriergroup.charging.<tenant>"]
    }
  }
}
EOF
```

Example of the successful response:

```json
{
   "id": "1",
   "jsonrpc": "2.0",
   "result": "true"
}
```

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31801` - The charging account with the given `ChargingAccountId` already exists.
- `-31802` - There is no registered tariff with the given `TariffId`.
- `-31803` - The `Valid-From` or `Valid-Till` date range is invalid.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Charging.Account.Read

The method allows you to fetch a charging account object associated with the given `ChargingAccountId`. If the charging account with such an identifier is not found in the system, TPOSS returns an error. If the charging account has associated balances, TPOSS returns them in the response.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
|---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| ChargingAccountId | string | required | Unique identifier for the charging account. |

Example of the request:

```bash
curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": "1",
  "jsonrpc": "2.0",
  "method":"Charging.Account.Read",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "ChargingAccountId": "700030010@account.charging.subscriber.<tenant>",
  }
}
EOF
```

Example of the successful response:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "result": {
    "ChargingAccountId": "700030010@.account.charging.<tenant>",
    "TariffId": "online",
    "ValidFrom": "2015-03-01T18:12:00Z",
    "ValidTill": "2018-07-31T23:59:59Z",
    "Balances": [
      {
        "BalanceId": "13@balance.charging.<tenant>",
        "BalanceDefinitionId": 3,
        "IMSI": "262019876543210",
        "CarrierGroupId": "27@carriergroup.charging.<tenant>",
        "ValidityTime": 86400,
        "ValidFrom": "2017-12-01T00:00:00Z",
        "ValidTill": "2017-12-31T23:59:59Z",
        "TotalOctets": 52428800,
        "InitialBalanceId": null
      }
    ]
  }
}
```

If a balance was provisioned with `IMEI` and the charging account was provisioned with tariff options, the response also contain them:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "result": {
    "ChargingAccountId": "700030010@.account.charging.<tenant>",
    "TariffId": "online",
    "ValidFrom": "2015-03-01T18:12:00Z",
    "ValidTill": "2018-07-31T23:59:59Z",
    "TariffOptions": {
      "UnlimitedStreaming": true,
      "UnlimitedStreamingCarrierGroups": ["27@carriergroup.charging.<tenant>"]
    },
    "Balances": [
      {
        "BalanceId": "13@balance.charging.<tenant>",
        "BalanceDefinitionId": 3,
        "IMSI": "262019876543210",
        "CarrierGroupId": "27@carriergroup.charging.<tenant>",
        "ValidityTime": 86400,
        "ValidFrom": "2017-12-01T00:00:00Z",
        "ValidTill": "2017-12-31T23:59:59Z",
        "TotalOctets": 52428800,
        "InitialBalanceId": null,
        "Labels": {
          "IMEI": "2620198765432101"
        }
      }
    ]
  }
}
```

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31804` - Charging account for the given `ChargingAccountId` was not found.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Charging.Account.Delete

The method allows you to mark the charging account associated with the given `ChargingAccountId` as deleted. TPOSS returns an error if the charging account is not found.

> [!NOTE]
> TPOSS CCS subsystem **does not** delete charging accounts from the database based on the API call. Instead, the objects are only marked as `deleted` and no longer visible to API consumers. An internal process finally deletes these objects from the database.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
|---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| ChargingAccountId | string | required | Unique identifier for the charging account. |

Example of the request:

```bash
curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": "1",
  "jsonrpc": "2.0",
  "method": "Charging.Account.Delete",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "ChargingAccountId": "700030010@account.charging.<tenant>"
  }
}
EOF
```

Example of the successful response:

```json
{
  "id": "101",
  "jsonrpc": "2.0",
  "result": "true"
}
```

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31804` - Charging account for the given `ChargingAccountId` was not found.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Charging.Account.Update

The method allows you to update a charging account associated with the given `ChargingAccountId`. If the charging account with the given identifier is not found, TPOSS returns an error.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
|---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| ChargingAccountId | string | required | Unique identifier for the charging account. |
| TariffId | string | required | Unique identifier for the tariff associated with the charging account. |
| ValidFrom | string | required | Validity range start date in the ISO 8601 format. |
| ValidTill | string | required | Validity range end date in the ISO 8601 format. |
| TariffOptions | object | optional | Tariff options. |

Example of the request:

```bash
curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": "1",
  "jsonrpc": "2.0",
  "method": "Charging.Account.Update",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "ChargingAccountId": "700030010@.account.charging.<tenant>",
    "TariffId": "online",
    "ValidFrom": "2015-03-01T18:12:00Z",
    "ValidTill": "2018-07-31T23:59:59Z",
    "TariffOptions": {
      "UnlimitedStreaming": false,
      "UnlimitedStreamingCarrierGroups": ["27@carriergroup.charging.<tenant>"]
    }
  }
}
EOF
```

Example of the successful response:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "result": "true"
}
```

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31802` - The requested tariff is not provisioned.
- `-31803` - The `Valid-From` or `Valid-Till` date range is invalid.
- `-31804` - Charging account for the given `ChargingAccountId` was not found.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.
