CDR Rating APIs
APIs for submitting and rating Call Detail Records (CDRs).
Overview
| Endpoint | Purpose |
|---|---|
chargeCdr | Rate CDR immediately |
registerCdrList | Register CDRs for deferred processing |
reserveCdr | Reserve prepaid balance |
processCdrList | Process 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
| Parameter | Type | Default | Description |
|---|---|---|---|
isVirtual | boolean | false | Virtual rating - no persistence, for quotes/testing |
rateTriggeredEdr | boolean | false | Rate triggered EDRs (bundles) |
maxDepth | int | - | Triggered EDR recursion depth |
returnEDRs | boolean | false | Return created EDR IDs |
returnWalletOperations | boolean | false | Return WO IDs |
returnWalletOperationDetails | boolean | false | Return full WO details (even if virtual) |
returnCounters | boolean | false | Return updated counter values |
generateRTs | boolean | false | Auto-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
- Quote Preview - Show customer estimated charges before subscription
- Prepaid Validation - Check if balance covers usage without consuming
- Testing - Test pricing configurations safely
- 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
reserveCdr→ CreatesReservationentity- Customer uses service
confirmReservation→ Consumes reserved amount- OR
cancelReservation→ Refunds reservation
Related Endpoints
POST /reserveCdr- Create reservationPOST /confirmReservation- Confirm and consumePOST /cancelReservation- Cancel and refund
Processing Modes
| Mode | Behavior |
|---|---|
STOP_ON_FIRST_FAIL | Default - stops on first error |
PROCESS_ALL | Continue despite errors, return all errors |
ROLLBACK_ON_ERROR | Atomic - 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