Skip to main content

CDR Rating APIs

APIs for submitting and rating Call Detail Records (CDRs).

Overview​

EndpointPurpose
chargeCdrRate CDR immediately
registerCdrListRegister CDRs for deferred processing
reserveCdrReserve prepaid balance
processCdrListProcess registered CDRs

chargeCdr - Rate CDR Immediately​

Endpoint​

POST /api/rest/v2/billing/mediation/chargeCdr

Purpose​

Parse CDR → Create EDR → Rate → Create WalletOperation in one call.

Query Parameters​

ParameterTypeDefaultDescription
isVirtualbooleanfalseVirtual rating - no persistence, for quotes/testing
rateTriggeredEdrbooleanfalseRate triggered EDRs (bundles)
maxDepthint-Triggered EDR recursion depth
returnEDRsbooleanfalseReturn created EDR IDs
returnWalletOperationsbooleanfalseReturn WO IDs
returnWalletOperationDetailsbooleanfalseReturn full WO details (even if virtual)
returnCountersbooleanfalseReturn updated counter values
generateRTsbooleanfalseAuto-generate RatedTransactions

Request Body​

CDR string in CSV format:

2024-01-15T10:30:00;SUB_001;100;API_CALL;GPT-4

Response​

{
"amountWithoutTax": 15.50,
"amountTax": 3.10,
"amountWithTax": 18.60,
"walletOperationCount": 3,
"walletOperations": [
{
"id": 12345,
"chargeInstance": "USAGE_CHARGE",
"quantity": 100,
"amountWithoutTax": 15.50
}
],
"edrIds": [12345, 12346],
"counterPeriods": [
{
"counterCode": "MONTHLY_USAGE",
"periodStart": "2024-01-01",
"value": 500
}
],
"error": null
}

Error Response​

{
"error": {
"errorCode": "SUBSCRIPTION_NOT_FOUND",
"errorMessage": "Subscription SUB_999 not found",
"cdr": "2024-01-15T10:30:00;SUB_999;100;API_CALL"
}
}

isVirtual Parameter (CRITICAL for Quotes)​

When isVirtual=true​

  • ❌ NO CDRs persisted to database
  • ❌ NO EDRs persisted
  • ❌ NO WalletOperations persisted
  • ❌ NO counters actually decremented
  • ✅ All calculations happen in-memory
  • ✅ Returns what charges WOULD be
  • ✅ Safe for quote simulation

Use Cases​

  1. Quote Preview - Show customer estimated charges before subscription
  2. Prepaid Validation - Check if balance covers usage without consuming
  3. Testing - Test pricing configurations safely
  4. What-If Scenarios - Calculate hypothetical charges

Example - Quote Simulation​

curl -X POST "${BASE_URL}/api/rest/v2/billing/mediation/chargeCdr?isVirtual=true&returnWalletOperationDetails=true" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: text/plain" \
-d "2024-01-15T10:30:00;SUB_001;1000;API_TOKENS;GPT-4"

registerCdrList - Batch Registration​

Endpoint​

POST /api/rest/v2/billing/mediation/registerCdrList

Purpose​

Register CDRs for later processing (deferred rating).

Request Body​

{
"cdr": [
"2024-01-15T10:30:00;SUB_001;100;API_CALL;GPT-4",
"2024-01-15T10:31:00;SUB_001;200;API_CALL;GPT-4",
"2024-01-15T10:32:00;SUB_002;50;API_CALL;GPT-3.5"
]
}

Response​

{
"status": "SUCCESS",
"message": "3 CDRs registered"
}

Workflow​

CDRs registered → stored with status OPEN → later processed via processCdrList

reserveCdr - Prepaid Reservation​

Endpoint​

POST /api/rest/v2/billing/mediation/reserveCdr

Purpose​

Reserve balance for prepaid without consuming.

Flow​

  1. reserveCdr → Creates Reservation entity
  2. Customer uses service
  3. confirmReservation → Consumes reserved amount
  4. OR cancelReservation → Refunds reservation
  • POST /reserveCdr - Create reservation
  • POST /confirmReservation - Confirm and consume
  • POST /cancelReservation - Cancel and refund

Processing Modes​

ModeBehavior
STOP_ON_FIRST_FAILDefault - stops on first error
PROCESS_ALLContinue despite errors, return all errors
ROLLBACK_ON_ERRORAtomic - rollback entire batch on any error

Example with Processing Mode​

curl -X POST "${BASE_URL}/api/rest/v2/billing/mediation/chargeCdr" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"cdrs": [
"2024-01-15T10:30:00;SUB_001;100;API_CALL",
"2024-01-15T10:31:00;SUB_002;200;API_CALL"
],
"mode": "PROCESS_ALL",
"returnEDRs": true
}'

Batch Processing Architecture​

Threading Strategy​

  • PROCESS_ALL: Multi-threaded (1 thread per CPU core)
  • STOP_ON_FIRST_FAIL: Single-threaded
  • Each CDR in separate transaction (except ROLLBACK_ON_ERROR)

Flow Diagram​

CDR Strings
↓ Parse
EDRs
↓ isVirtual=false?
├── YES: Persist to DB → Rate → Save WOs
└── NO: In-Memory Only → Rate → Return Details

Bash Script Examples​

Virtual Rating for Quote​

#!/bin/bash
source ./setup-env.sh

SUBSCRIPTION=$1
QUANTITY=$2

CDR="$(date -Iseconds);${SUBSCRIPTION};${QUANTITY};API_CALL;DEFAULT"

curl -s -X POST "${OPENCELL_BASE_URL}/api/rest/v2/billing/mediation/chargeCdr?isVirtual=true&returnWalletOperationDetails=true" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: text/plain" \
-d "$CDR" | jq

echo "NOTE: isVirtual=true - no data persisted"

Batch CDR Processing​

#!/bin/bash
source ./setup-env.sh

CDR_FILE=$1
MODE=${2:-"PROCESS_ALL"}

CDR_LINES=$(cat "$CDR_FILE" | jq -R -s 'split("\n") | map(select(length > 0))')

curl -s -X POST "${OPENCELL_BASE_URL}/api/rest/v2/billing/mediation/chargeCdr" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"cdrs": '"$CDR_LINES"',
"mode": "'$MODE'",
"returnEDRs": true,
"returnWalletOperations": true
}' | jq