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

# Carriers API

TPOSS Carriers API allows you to import and manage carriers and carrier groups using the following RPC methods:

- [Charging.CarrierGroup.Import](#chargingcarriergroupimport) - to import carriers and carrier groups into TPOSS database

## Data model

A carrier group is represented by an object with the following properties:

|Attribute | Type | Description
|---|---|---
| CarrierGroupId | string | Carrier group identifier.
| CarrierGroupName | string | Name for the carrier group.
| Carriers | list | List of carriers. For more information, see the table below.

A carrier is represented by an object with the following properties:

|Attribute | Type | Description
|---|---|---
| CarrierName | string | Name of the carrier.
| CountryName | string | Name of the country.
| CountryCode | string | Code of a country in the ISO 3166-1 Alpha-2 format.
| Mnc | string | MNC of a carrier.
| MccMnc | string | MCC/MNC combination as defined in a RADIUS Requests.

## API methods

### Charging.CarrierGroup.Import

This method allows you to import a complete list of carrier groups with the related carriers. The method checks the difference between the carrier groups and carriers data passed in the request with the data from the TPOSS database. The result is applied to the database so that carrier groups and carriers in CCS are the same as in the source JSON data from the original request.

For each carrier from the provided source data within a carrier group, the following checks are performed when importing the data:

- If a carrier already exists in the database with identical values, the record is skipped.
- If a carrier already exists in the database with different values, the record for this carrier is updated.
- If a carrier does not exist, the carrier is inserted into a carrier group.
- If a carrier exists in the carrier group but not in the provided source data, the carrier is deleted from the carrier group.

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. |
| CarrierGroups | list | required | List of carrier groups. |

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.CarrierGroup.Import",
  "params": {
    "AuthKey": "secret",
    "FeId": "bss1.<tenant>",
    "FeSId": "13.bss1.<tenant>",
    "CarrierGroups": [
      {
        "CarrierGroupId": "27@carriergroup.charging.<tenant>",
        "CarrierGroupName": "Europe",
        "Carriers": [
          {
            "CountryName": "GERMANY",
            "CarrierName": " Telekom Deutschland GmbH ",
            "CountryCode": "DE",
            "Mnc": "01",
            "MccMnc": "26201"
          },
          {
            "CountryName": "AUSTRIA",
            "CarrierName": "T-Mobile Austria",
            "CountryCode": "AT",
            "Mnc": "03",
            "MccMnc": "23203"
          }
        ]
      }
    ]
  }
}
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.
- `-33333` - Not authenticated.
- `-32700` - Can't decode JSON request body.
