Connecting to 3CX Version 20 API Using PHP for Custom Database Reports

Hi there!

I have 3CX version 20 set up and I want to build custom reports using PHP with MySQL. I need to pull data like call metrics, time spent on calls, and queue information.

Can I connect directly to the 3CX API to get this data? My goal is to grab the information from their API and save it to my own MySQL database. Then I can create my own reporting dashboards.

Or do I have to use Grafana instead and stick with their built-in data connections?

Any help would be great!

been using 3CX API for months - it’s rock solid. One thing nobody mentioned: handle SSL certificates right or you’ll get weird connection drops. the webhook feature is a game changer if you need real-time data instead of constant polling. saves tons of server resources.

Yes, you can absolutely connect to the 3CX v20 API using PHP. I have successfully implemented this for several projects. The REST API provides access to essential data such as call records, queue statistics, and agent metrics via authenticated endpoints. Begin by creating API credentials within the 3CX management console, and utilize cURL or any preferred HTTP client library for your requests. Be mindful that authentication relies on bearer tokens that have an expiration period, so ensure you implement token refresh logic. Storing data in MySQL is effective for building custom reports as it allows you full control over the database schema. Although the API documentation may seem sparse initially, getting the authentication process right makes fetching call detail records and queue statistics straightforward. Just keep rate limits in mind and consider batching requests if you’re dealing with large volumes of data.

I’ve worked with 3CX v20 API a ton - here’s what you need to know. First, check their rate limit docs because they’re really strict about concurrent requests. The CDR endpoint will timeout if you pull too much historical data at once, so break it into smaller chunks by date range. Watch out for timezones - 3CX saves everything in UTC but you’ll want local time for reports. Some queue metrics aren’t in the standard call records either, you have to hit the statistics endpoint separately. Auth tokens expire every 24 hours, so make sure you handle 401 errors properly. MySQL is perfect for this and way more flexible than Grafana’s widgets.

I’ve used 3CX v20 for two years - the API works great. First, enable API access in Management Console > Settings > General > API. Write down that API key because it disappears after setup. For PHP, use Guzzle HTTP client instead of basic cURL. It handles auth headers way better. Watch out for permission levels - different endpoints need different access, so test your API user setup thoroughly. The call detail records endpoint will do exactly what you want. Skip Grafana - your own MySQL database gives you way more control for custom reports and connecting to other business tools.

The 3CX v20 API docs have gaps but they’ll work for what you need. I spent way too much time figuring out the endpoint structure - their examples don’t cover everything. Test with a simple ping first before you jump into complex queries. Call metrics come back as JSON, so MySQL insertion is pretty straightforward with prepared statements. Watch out for this gotcha: some call duration fields are in milliseconds, others in seconds. Normalize everything before storing. The API sometimes returns partial data during maintenance windows, so add proper error checking. Building your own dashboard definitely beats Grafana’s limitations, especially when you need custom business logic mixed with call data.