> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.16/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/6.16/api-reference/cdr_api.md).

# CDR API

TPOSS CDR API allows you to read and delete Charging Data Records (CDRs) generated by TPOSS. To do so, you must first enable the [database backend](https://docs.cennso.com/components/tposs/6.16/configuration/charging.md#charging-data-records-configuration) for them. Then, you can manage CDRs using the following RPC methods:

- [Cdr.Read](#cdrread)  - to fetch a CDR by the given identifier
- [Cdr.BulkRead](#cdrbulkread) - to fetch multiple CDRs by the given identifiers
- [Cdr.List](#cdrlist) - to fetch the list of CDRs filtered by the given criteria
- [Cdr.Delete](#cdrdelete) - to delete a CDR by the given identifier

## Data model

A CDR is represented by an object with the following attributes:

| Attribute |Type | Description
|---|---|---
| CdrId | string | Unique ID of the CDR represented by the UUIDv4.
| SessionId | string | Session identifier that identifies the PCS session object.
| SubscriberId | string | Subscriber identifier used to group a set of users.
| ChargingAccountId | string | Unique identifier for the charging account.
| TariffId | string | Unique identifier for the tariff associated with the charging account.
| UserId | string | User identifier. It represents a device that a customer uses to access services.
| Username | string | Public name of the user.
| ServiceId | string | Identifier for the used service.
| UsedVolumeIn | uint64 | Incoming traffic in bytes consumed by the subscriber.
| UsedVolumeOut | uint64 | Outgoing traffic in bytes consumed by the subscriber.
| StartTime | string | UTC time when the CDR was started.
| SessionTime | uint32 | Duration of the service usage in seconds.
| EndTime | string | UTC time when the CDR was closed.
| TerminationCause | string | Reason for the CDR generation.
| Ip | string | IP address of the device associated with the session.
| NatIp | string | NAT IP address of the device associated with the session when using port-based NAT.
| NatPortRangeStart | uint16 | Start of port range when using port-based NAT.
| NatPortRangeEnd | uint16 | End of port range when using port-based NAT.
| BalanceId | string | Unique identifier for the balance object.
| Homecountry | string | Code of user home country in the ISO 3166-1 Alpha-2 format.
| InitialBalanceId | string | ID of parent balance.
| ExcessVolumeIn | uint64 | Number of incoming bytes exceeding the permitted number of bytes consumed by the subscriber.
| ExcessVolumeOut | uint64 | Number of outgoing bytes exceeding the permitted number of bytes consumed by the subscriber.
| ExcessVolumeTotal | uint64 | Total number of bytes exceeding the permitted number of bytes consumed by the subscriber.
| IMSI | string | Unique identifier of a SIM card.
| IMEI | string | Unique identifier of a user device (15 digits).
| IMEISV | string | Unique identifier of a user device with Software Version Number (16 digits).
| CarrierGroupId | string | Carrier group identifier.
| MccMnc | string | MCC/MNC combination as defined in a RADIUS Requests.
| CalledStationId | string | APN name.
| CallingStationId | string | A Layer 2 address from which the subscriber is connected. It can be a MAC address or a phone number.

## API methods

### Cdr.Read

The method allows you to fetch the CDR object by the given `CdrId`. If the CDR with the given ID is found, TPOSS returns it in the response. Otherwise, an error is returned.

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. |
| CdrId | string | required | Unique charging data record identifier. |

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": "Cdr.Read",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "CdrId": "07d18201-8344-4a7f-b112-92dd745812ec",
  }
}
EOF
```

Example the of the successful response:

```json
{
   "id": "101",
   "jsonrpc": "2.0",
   "result": {
       "CdrId": "07d18201-8344-4a7f-b112-92dd745812ec"
       "SessionId": "tpnet-6uR0lPmIpufi3MLt@session.<tenant>",
       "SubscriberId": "700030010@subscriber.<tenant>",
       "ChargingAccountId": "700032310@account.charging.<tenant>",
       "TariffId": "online@tariff.<tenant>",
       "UserId": "701976710@user.<tenant>",
       "Username": "262019876543210",
       "ServiceId": "Online@service.<tenant>",
       "UsedVolumeIn": 4746862,
       "UsedVolumeOut": 46862,
       "StartTime": "2015-05-07 20:43:22Z",
       "SessionTime": 3600,
       "EndTime": "2015-05-07 21:43:22Z",
       "TerminationCause": "Session-Timeout",
       "Ip": "62.12.2.22",
       "NatIp": "172.16.1.12",
       "NatPortRangeStart": 12210,
       "NatPortRangeEnd": 12250,
       "BalanceId": "13@balance.charging.<tenant>"
       “IMSI”: “262019876543210“,
       “IMEI”: “354311050022709“,
       “IMEISV”: “3543110500227002“,
       "Homecountry": "DE",
       "CarrierGroupId": "27@carriergroup.charging.<tenant>",
       "MccMnc": "23203",
       "InitialBalanceId": "3",
       "ExcessVolumeIn": 0,
       "ExcessVolumeOut": 0,
       "ExcessVolumeTotal": 15,
       "Called-Station-Id": "apn.example.com",
       "CallingStationId": "00-10-A4-23-19-C0"
   }
}
```

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.
- `-31601` - CDR is not found for the given `CdrId`.
- `-31810` - Validation error.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Cdr.BulkRead

This API is the same as [Cdr.Read](#cdrread) but allows you to pass a list of `CdrIds` in the request body. The API call returns a list of CDRs associated with the given CDR identifiers. In addition, TPOSS returns a list of CDR identifiers not associated with any CDR.

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. |
| CdrIds | List | required | List of requested CDR IDs (strings). |

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": "Cdr.BulkRead",
    "params": {
       "AuthKey": "secret",
       "FeId": "bss1.<tenant>",
       "FeSId": "13.bss1.<tenant>",
       "CdrIds": [
          "07d18201-8344-4a7f-b112-92dd745812ec",
          "32118201-1234-4a7f-b112-92dd745812ec"
       ]
    }
}
EOF
```

Example of the successful response:

```json
{
  "id": "101",
  "jsonrpc": "2.0",
  "result": {
    "TotalRcords": 1,
    "TotalErrors": 1,
    "Records": [
      {
        "CdrId": "07d18201-8344-4a7f-b112-92dd745812ec"
        "SessionId": "tpnet-6uR0lPmIpufi3MLt@session.<tenant>",
        "SubscriberId": "700030010@subscriber.<tenant>",
        "ChargingAccountId": "700032310@account.charging.<tenant>",
        "TariffId": "online@tariff.<tenant>",
        "UserId": "701976710@user.<tenant>",
        "Username": "262019876543210",
        "ServiceId": "Online@service.<tenant>",
        "UsedVolumeIn": 4746862,
        "UsedVolumeOut": 46862,
        "StartTime": "2015-05-07 20:43:22Z",
        "SessionTime": 3600,
        "EndTime": "2015-05-07 21:43:22Z",
        "TerminationCause": "Session-Timeout",
        "Ip": "62.12.2.22",
        "NatIp": "172.16.1.12",
        "NatPortRangeStart": 12210,
        "NatPortRangeEnd": 12250,
        "BalanceId": "13@balance.charging.<tenant>"
        “IMSI”: “262019876543210“,
        “IMEI”: “354311050022709“,
        “IMEISV”: “3543110500227002“,
        "Homecountry": "DE",
        "CarrierGroupId": "27@carriergroup.charging.<tenant>",
        "MccMnc": "23203",
        "InitialBalanceId": "3",
        "ExcessVolumeIn": 0,
        "ExcessVolumeOut": 0,
        "ExcessVolumeTotal": 15,
        "Called-Station-Id": "apn.example.com",
        "CallingStationId": "00-10-A4-23-19-C0"
      }
    ],
    "Errors": [
      "32118201-1234-4a7f-b112-92dd745812ec"
    ]
  }
}
```

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.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Cdr.List

The method is similar to the [Cdr.BulkRead](#cdrbulkread) API call. The difference is that the `Cdr.List` method allows you to filter CDRs not only by the identifier but also by other parameters defined in the [data model](#data-model). In addition, you can pass the `Limit` and `Offset` parameters. If the number of results exceeds the internal query limit, only the initial subset is returned. TPOSS returns an error if no valid query parameter is passed.

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. |
| Limit | uint16 | optional | Limits the size of the result. |
| Offset | uint16 | optional | Number of results skipped in the response. |
| Sort | string | optional | Defines the sorting order of the results based on a specific attribute. |
| Filter | string | optional | Defines a filter applied to the query results. |
| Fields | string | optional | Defines a list of fields which should be returned. |

The `Sort` field defines the sorting order by a given field value. For example, to sort the CDRs by `SubscriberId`, the `"Sort.SubscriberId:asc"` parameter must be passed in the body request. The format is `FieldName:SortOrder`, where `FieldName` represents the field name of a CDR and the `SortOrder` value can be either `asc` or `desc`. The possible fields are listed in the [data model](#data-model) section.

The `Filter` field allows you to filter the CDRs. The filter format is: `FilterKey:FilterOperator:FilterValue`. The `FilterKey` represents the field name of a CDR. The possible fields are listed in the [data model](#data-model) section. The `FilterOperator` can have the following values:

- `is` - equal to
- `neq` - not equal to
- `lte` - lower than or equal to
- `gt` - greater than
- `lt` - lower than
- `gte` - greater than or equal to
- `starts_with` - match objects which start with the given pattern
- `ends_with` - match objects which end with the given pattern
- `contains` - match objects which contain the given pattern

The value of the `FilterValue` parameter specifies what to filter from the results.

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": "Cdr.List",
    "params": {
       "AuthKey": "secret",
       "FeId": "bss1.<tenant>",
       "FeSId": "13.bss1.<tenant>",
       "Filter": "SubscriberId:is:700030010@subscriber.int.str.carisp.net"
    }
}
EOF
```

Example of the successful response:

```json
{
   "id": "101",
   "jsonrpc": "2.0",
   "result": {
      "TotalRcords": 1,
      "Records": [
         {
            "CdrId": "07d18201-8344-4a7f-b112-92dd745812ec"
            "SessionId": "tpnet-6uR0lPmIpufi3MLt@session.<tenant>",
            "SubscriberId": "700030010@subscriber.<tenant>",
            "ChargingAccountId": "700032310@account.charging.<tenant>",
            "TariffId": "online@tariff.<tenant>",
            "UserId": "701976710@user.<tenant>",
            "Username": "262019876543210",
            "ServiceId": "Online@service.<tenant>",
            "UsedVolumeIn": 4746862,
            "UsedVolumeOut": 46862,
            "StartTime": "2015-05-07 20:43:22Z",
            "SessionTime": 3600,
            "EndTime": "2015-05-07 21:43:22Z",
            "TerminationCause": "Session-Timeout",
            "Ip": "62.12.2.22",
            "NatIp": "172.16.1.12",
            "NatPortRangeStart": 12210,
            "NatPortRangeEnd": 12250,
            "BalanceId": "13@balance.charging.<tenant>"
            “IMSI”: “262019876543210“,
            “IMEI”: “354311050022709“,
            “IMEISV”: “3543110500227002“,
            "Homecountry": "DE",
            "CarrierGroupId": "27@carriergroup.charging.<tenant>",
            "MccMnc": "23203",
            "InitialBalanceId": "3",
            "ExcessVolumeIn": 0,
            "ExcessVolumeOut": 0,
            "ExcessVolumeTotal": 15,
            "Called-Station-Id": "apn.example.com",
            "CallingStationId": "00-10-A4-23-19-C0"
         }
      ]
   }
}
```

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.
- `-31411` - Invalid query.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Cdr.Delete

The method allows you to delete the CDR associated with the `CdrId` identifier.

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. |
| CdrId | string | required | Unique charging data record identifier. |

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": "Cdr.Delete",
  "params": {
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "CdrId": "07d18201-8344-4a7f-b112-92dd745812ec"
  }
}
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.
- `-31601` - CDR is not found for the given `CdrId`.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.
