Customizing CDR (Call Data Records) output
3CX Phone System can output call data records per call. These call data records can be configured to a format of your choice and thus its relatively easy to integrate with external billing software.
Adjusting Billing costs
3CX Phone System calculates call costs based on destination number and call duration. You will need to enter the cost for each country, for national calls and for mobile calls. The default billing rate is 1.0 (meaning <currency>1.00 per minute) for all countries. To change these rates
- In 3CX Management Console, go to menu option “View -> Billing Information”
- Edit the rates as appropriate and click “Apply”.
- When calls are made to external numbers, they are checked against this prefix table. If a match is found then the cost is calculated as follows:
TotalCost = Talking time * rate
CDR Output
The CDR feature provides three output types.
- One file containing all calls
- Each call in a separate file
- Socket output
Each channel can be enabled separately. To enable any of the CDR output channels, from the management console go to the “Settings -> Advanced” page, and select the “CDR Output” tab. Finally, once you have done this, restart the Call History Service from the “Services Status” page.
Where are the CDR Template files?
The template files are located in:
- Windows XP / 2003 : C:\Documents and Settings\All Users\Application Data\3CX\Data\CDRTemplates
OR
- Windows Vista / 2008 / 7 : C:\ProgramData\3CX\Data\CDRTemplates
All output is text based and can be formatted by modifying the template for each output type.
Changing CDR output location
The default output location can be changed by editing each template file. This table shows where to find the three CDR template files, and the default location where CDR data is generated by default:
| Output Type | Template File | Default Output Location |
| One File | …\CDRTemplates\CDRTemplate-Single.xml | …\Logs\CDRSingle\calls.txt |
| Per Call | …\CDRTemplates\CDRTemplate-PerCall.xml | …\Logs\CDRMulti\calls.txt |
| Socket | …\CDRTemplates\CDRTemplate-Socket.xml | TCP::127.0.0.1:33555 |
Example 1: Changing CDR Output Location for the “Socket” output type
If you wanted to change the IP Address and Port for Socket delivery of CDR data:
- Open the “CDRTemplate-Socket.xml” file
- Identify the “CallTemplate” tag (typically on the second line of the template file)
- Change the value of the “Host” parameter to the IP Address of the target CDR Listener Service
- Change the value of the “Port” parameter to the Port Number of the target CDR Listener Service
So if in this example there was a CDR Listener Service on IP Address “192.168.1.22″ listining on port “40000″, this would change the “CallTemplate” tag from:
<CallTemplate Host=”127.0.0.1″ Port=”33555″ OutboundOnly=”false”>
to
<CallTemplate Host=”192.168.1.22″ Port=”40000″ OutboundOnly=”false”>
Example 2: Changing CDR Output Location for the “One File” output type
If you wanted to change the location where to save the file containing CDR Data:
- Open the “CDRTemplate-Single.xml” file
- Identify the “CallTemplate” tag (typically on the second line of the template file)
- Change the value of the “Folder” parameter to the target folder
- Change the value of the “FileName” parameter to the target filename (inside the target folder specified above)
So if in this example you wanted to save CDR Data into the “C:\Documents and Settings\All Users\Application Data\3CX\Data\Logs\CustomLogs\MyCalls.txt” file, this would change the “CallTemplate” tag from:
<CallTemplate Folder=”3CX\Data\Logs\CDRSingle\” FileName=”calls.txt” OutboundOnly=”false”>
to
<CallTemplate Folder=”3CX\Data\Logs\CustomLogs\” FileName=”MyCalls.txt” OutboundOnly=”false”>
Please note that the “Folder” parameter must be relative to the base folder, which is:
- Windows XP / 2003: “C:\Documents and Settings\All Users\Application Data\”
OR
- Windows Vista / 2008 / 7: “C:\ProgramData\”
So if you wanted to save CR Data into the “C:\CustomLogs\MyCalls.txt” file, this would change the “Folder” parameter to:
- Windows XP / 2003: “..\..\..\CustomLogs\”
OR
- Windows Vista / 2008 / 7: “..\CustomLogs\”
Editing a CDR Template
Each of the 3 Template files contains XML tags that describe which database fields should be included in the CDR, in which order, and how each field should be formatted. Keep in mind that each call has one main “Callhistory3″ record and 1 or more “CallDetails” entries.
The formatting is achieved using C# formatting strings.
Example 1: Formatting the “TotalCost” field
<TotalCost fmt=”CallCost = {0}”/>
Example 2: Adding “NewLine” characters in XML:
<NumDetails fmt=”Call details = {0}
” />
Modifications to the CDR/SDMR script file
Due to the wide variety of 3rd party applications available out there for integration with 3CX, it is not possible to develop a script that accommodates everyone. The script requires C# development knowledge and .NET formatting to be manipulated.
3CX can develop this script and adjust it (or add functionality) based on your demands. Download the form from here, fill it up answering all sections in full detail and send this to sales@3cx.com. You will receive an answer shortly.

Hi. Can we setup a phone shop feature. i.e. if the customer wants to add a markup to bill his clients for calls made from his internet shop
Yes, you can. You just have to pick up the CDR records being outputted and then you can add the charge to the bill.
Excellent article. Could you provide some samples of generated output as well?
Second question, is there an API or specific file that can be used/edited to set the call rates automatically through custom software?
To achieve this you would need to investigate the Call Control API. More information here:
http://www.3cx.com/blog/docs/take-control-of-calls-on-3cx-with-the-call-control-api/
You can edit the call rates from the interface. They are actually stored in the database.
You could analyze the CDR records and when you feel an extension should be disabled you could disable it using the HTTP API or the Call API
In addition, the CDR record specifies the number and call duration so you can apply your own costing if you want….
Good point Nick. It would indeed be the easiest to just parse the call data and process the tariffs separate from 3CX. I just ran a test to get a sample output. It could be handy to add some info on how to output the information in XML instead of plain text so that XSL(T) can easily be applied and mistakes in what data is represented by what line are minimized.
Hi Koen,
Using the description above you can edit the output to anything you want just by editing the template. If you want to post process the file it is also possible by writing a C# script…