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

# API overview

TPOSS provides two types of API:

- [JSON-RPC 2.0 API](https://www.jsonrpc.org/specification) to manage [UDR, CCS, and PCS](https://docs.cennso.com/components/tposs/6.16/glossary.md#abbreviations) data
- [SBI API](https://docs.cennso.com/components/tposs/6.16/architecture/sbi.md)

>**NOTE:** The documents in the **API Reference** section describe only the TPOSS JSON-RPC 2.0 API to manage UDR, CCS, and PCS data. All the subsequent mentions of "TPOSS API" or "API" are related only to this type of API. To learn more about TPOSS SBI API, read the [SBI API](https://docs.cennso.com/components/tposs/6.16/architecture/sbi.md) architecture document.

TPOSS provides the following APIs:

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

All the RPC APIs are accessible through the [TPOSS API Gateway](https://docs.cennso.com/components/tposs/6.16/installation/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 behaviour, 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:

- `UserPublicId`
- `ChargingAccountId`
- `Sort`

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

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

All the parameters, method and attribute names are described in the following API documents.

## 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 behaviour and allows easier auditing of request logs.

## Authentication

TPOSS APIs are authenticated based on secret API keys. Before a client is authenticated, it needs an authentication key. Such a key must be configured in the TPOSS API [configuration](https://docs.cennso.com/components/tposs/6.16/configuration/api.md) by a TPOSS operator. Each request must contain the `AuthKey` field and the `FeId` field to authenticate the API user. Both authentication identifiers are configured at the TPOSS side using the following configuration option:

```yaml
tposs_http_api:
  secret_keys: "clientid-secret, tt-secret"
```

The **tposs_http_api.secret_keys** is a list of the `FeId` and `AuthKey` split by a dash and separated by a comma. For example, in `clientid-secret`, the `clientid` is `FeId` and the `secret` is `AuthKey`. If the client does not provide them or provides unknown values for TPOSS, TPOSS returns the `-33333 Not authenticated` error.

After you configure TPOSS with the given API authentication keys, you must share the keys with the client so that it can use these keys for API requests. This procedure is out-of-band and not handled by the authentication API itself. Once an authentication key is obtained, a client can use it for authenticated API requests. All the TPOSS API methods require an authentication key to be passed along with the other parameters.

## 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/6.16/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.
