> 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/overview.md).

# JSON-RPC 2.0 API

TPOSS provides the following RPC APIs:

- [Balance API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/balance_api.md) - API to manage subscribers balances.
- [Carriers API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/carriers_api.md) - API to manage carriers and carrier groups.
- [CDR API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/cdr_api.md) - API to manage CDRs.
- [Charging Account API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/charging_account_api.md) - API to manage charging accounts.
- [Events API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/events_api.md) - API to manage TPOSS events.
- [Session API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/session_api.md) - API to manage PCS sessions.
- [Subscriber API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/subscriber_api.md) - API to manage subscribers.
- [Whitelist API](https://docs.cennso.com/components/tposs/latest/api-reference/rpc/whitelist_api.md) - API to manage TPOSS whitelisted IMEIsv.

TPOSS RPC APIs are accessible through the [TPOSS API Gateway](https://docs.cennso.com/components/tposs/latest/technical-reference/api-gw-configuration.md) component and not directly through TPOSS. All the APIs follow a uniform design. This design is meant to ease the adoption and consumption of the different APIs that TPOSS API Gateway exposes. The APIs are based on open protocols and common concepts to lower the barrier for developers.

All APIs follow the [JSON-RPC 2.0](https://www.jsonrpc.org/specification) protocol. The protocol itself is implemented by client libraries in various programming languages. The JSON-RPC 2.0 protocol specification defines the message flow between a client and a server. Whenever APIs require notification-like message behavior, the [Request-Response](https://en.wikipedia.org/wiki/Request%E2%80%93response) pattern is used to support endpoint acknowledgement as defined by the JSON-RPC 2.0 protocol. The notification messages defined in JSON-RPC 2.0 aren’t used. Since JSON-RPC 2.0 defines a message identification used to match Request-Response pairs, it is possible to multiplex RPC calls between a single client and the TPOSS server.

Each RPC API call is an HTTP POST request with the following fields:

- `jsonrpc` - a string specifying the JSON-RPC protocol version. It must be `2.0`.
- `id` - an identifier established by the client that must contain a number.
- `method` - a string representing the name of the RPC method implemented by TPOSS.
- `params` - a set of RPC call parameters.

The TPOSS APIs define RPC methods with their parameters and return types that the clients can call remotely. Whenever a client sends a request to the TPOSS API Gateway server, it can expect a response for that request. The underlying messaging protocol defines how a response is matched to a particular request.

## Naming rules

Parameter and attribute names are written in camel case. For example:

- `ChargingAccountId`
- `Sort`

Method names are prefixed with the API namespace they are part of. For example:

- `Subscriber.Read`
- `Cdr.List`

## Frontend identifiers

All the API requests require clients to identify themselves against the API. For this reason, clients may use identifiers that are then handled as opaque data by TPOSS. TPOSS uses these identifiers for request authorization and logging.

Clients must pass these two frontend identifiers in each request:

- `FeId` (Frontend Identifier) - must be a static value associated with the client application. For example: `CFP12`.
- `FeSId` (Frontend Session Identifier) - must be a dynamic value generated at the client's startup. It allows TPOSS to detect malfunctioning client behavior and allows easier auditing of request logs.

## Authentication

All the RPC API methods require an authentication key to be passed along with the other parameters. Each request must contain the `AuthKey` field and the `FeId` field in the `params` object. TPOSS API Gateway combines both fields into the authentication key that a TPOSS operator configures on the TPOSS side. If the client does not provide them or provides unknown values for TPOSS, TPOSS returns the `-33333 Not authenticated` error.

For more information about the authentication keys and their configuration, see the [API overview](https://docs.cennso.com/components/tposs/latest/api-reference/api.md#authentication) document.

## API parameters

All the TPOSS APIs have a set of defined input parameters described in the corresponding API documents. The parameters marked as `required` must be passed to the method; otherwise, TPOSS returns an error. The optional parameters are marked as `optional` and can be omitted in the API calls. TPOSS ignores input parameters that are not defined for the API method with no impact on the result of the API method execution. All the values that are not valid for an API method result in the error response. Additionally, the log message with the parameter and the parameter's value is printed at least at the [logging level](https://docs.cennso.com/components/tposs/latest/configuration/logging.md) - `debug`.

The most API methods support a set of common parameters to enable clients to narrow down request result sets as needed. These common parameters are:

- `Limit`
- `Offset`
- `Sort`
- `Filter`
- `Fields`

You can refer to the individual API specifications to find out which API methods support these parameters.

### Limit

The `Limit` parameter allows the client to specify an upper limit on the number of records returned in a response.

### Offset

The `Offset` parameter allows the client to specify a number of objects to skip before collecting the result entries. The offset is taken into account after sorting if the `Sort` parameter is passed.

### Sort

The `Sort` parameter allows the client to sort the results according to an attribute in the directions `asc` (ascending) or `desc` (descending). For example:

```
"Sort": "IMSI:asc"
```

This parameter allows you to sort the API request results according to IMSI from lower to higher values.

### Filter

The `Filter` parameter allows the client to apply specific filtering rules to the result. The following filter operations are supported:

- `is` - equal to
- `lte` - lower than or equal to
- `lt` - lower than
- `gte` - greater than or equal to
- `gt` - greater than
- `ends_with` - ends with a given pattern
- `starts_with` - starts with a given pattern
- `contains` - contains a given pattern

The `ends_with`, `starts_with`, and `contains` filter operators allow you to specify a pattern to match. For example:

```
"Filter": "IMSI:ends_with:5"
```

or

```
"Filter": "Username:starts_with:262"
```

All these filter operators work only with the string data but not with dates, timestamps, and IP addresses.

It's possible to specify more than one filter. Comma-separated filters are evaluated like logical `and`. For example:

```
"Filter": "NatIp:is:10.10.10.100,NatPortStart:lte:25140,NatPortEnd:gte:25140"
```

You may use this filter to get a session by a given NAT IP address and one known NAT port.

### Fields

The `Fields` parameter allows the client to specify a list of object attributes (separated by colons) which should be returned by a query. By removing attributes from irrelevant results, you can execute more efficient queries.

For example:

```
"Fields": "Username"
```

or:

```
"Fields": "Username:ChargingAccountId"
```

or:

```
"Fields": "Username:ChargingAccountId:SubscriberId"
```

## Common error scenarios

Despite each TPOSS API method may have its own set of possible errors, all the APIs methods share common error scenarios:

- `Authentication key not valid` - If the authentication key can’t be verified for the calling client, the server does not allow a client to access the requested API method. In this case, the `-33333` error code is returned.
- `Required field missed` - If a request should contain mandatory input parameters and at least one of them is missing, the server doesn't allow a client to access the requested API method. In this case, the `-30000` error code is returned.
- `Type mismatch error` - If a request has input parameters and at least one of their values has the wrong data type, the `-31810` error code is returned with the related error message.

All the possible errors related to the API methods are described in the respective TPOSS API documents.
