Toggl is a hosted time tracking system, used to keep track of time spent of different projects.
If you use Asterisk/FreePBX and spend time on the phone to clients that should be assigned to a project you can automatically create time entries in Toggl using their API. To do this we can make a curl call from Asterisk when a call ends.
To be able to do this you’ll need to ensure you have curl compiled in to Asterisk. You can check this with “core show function CURL”.
I tested this on Asterisk 11 and FreePBX v2.11, but it should work the same on other versions.
First we need to add a little dial plan code to Asterisk to tell it to run our script when a call ends. We going to do this by adding the following lines to – /etc/asterisk/extensions_custom.conf
After changing the dial plan we will either need to restart Asterisk or run “dialplan reload”.
That will call a web page on the local server called toggl.php, now we need to create that file. On my server it will look here for the file – /var/www/html/toggl.php
You will need to change the setting at the top to match your toggl API token.
Now when a call ends Asterisk calls the toggl.php web page, passing it the source, destination and length of the call. This is then formatted in the way that the toggl API expects and posted to toggl.
When a call ends you should immediately see a new time entry created in Toggl –
If your time entry doesn’t get created in toggl then check in the Asterisk logs to ensure the Curl request is being made, and check in the web server logs to ensure there are no errors when the script runs.