1. Install the Files to Your System


  • Download webapi files for Debian from here.
  • Extract all the files from the downloaded RAR archive.
  • Create a folder called webapi with the file path as follows.

/var/www/webapi/

  • Put the extracted files into the webapi folder you created at the beginning.
  • After copying the files to the webapi folder you've created, run this command.: 
Shell
chmod +x /var/www/webapi/WebhooksApi

 

  • For MP3 files, create a folder named "mp3" with the file path as follows:

/var/www/webapi/mp3

Important:

You need to give write permission to MP3 folder.

 

2. Install Nano for Editing


You can use the below command to install nano:

Shell
apt install nano

 

3. Editing Settings.ini File


  • Open the "Settings.ini" file by running the following command.

    Shell
    nano /var/www/webapi/Settings.ini

     

  • Change the value of the "LICENSE_KEY" parameter below with the license key given to you and save the file by pressing  Crtl+X then Y and Enter

    Settings.ini
    LICENSE_KEY=AAAA-AAAA-AAAA-AAAA
     
  • If you want to use WebHooks, you should set the "WEBHOOK_POST_ENABLED" setting under the WebHook section in this file to true. Just below it, you will find the "WEBHOOK_URL" field. You should write the URL address to which you want to send data from your PBX in this field. At the end of the process, the "webhooks" section within the file should look like the following.
Settings.ini
WEBHOOK_POST_ENABLED = true
WEBHOOK_URL = https://your-endpointto-post-data

 

4. Editing AccessKeys.csv File


Now you are ready to edit AccessKeys.csv. You can use nano to edit with following command:

Shell
nano /var/www/webapi/AccessKeys.csv

 

The "key" field within this file will be the access key you will use to access the APIs. Create an access key. After entering the email address and name information for this access key, the last section will be the permission field. In this field, you can configure which API endpoints you want to access with this key:

All: Grants access to all (SET, GET and CallControl) APIs.

Get: Grants access to APIs with names starting with "GET" as mentioned in the Postman documentation.

Set: Grants access to APIs with names starting with "SET" and "GET" as mentioned in the Postman documentation.

 

Important:

By default, all customers who install WebAPI will have an access key in the AccessKeys.csv file. We recommend either deleting or changing this key.

 

Press Crtl+X  then  Y and Enter to save and quit.

 

5. Install .NET SDK 6.0


You can install the SDK by running the following commands respectively.

Shell

wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update && sudo apt-get install -y dotnet-sdk-6.0

 

6. Creating a Daemon


  • Let's create the "webapi.service" file using the nano editor to create the daemon.
    Shell

    nano /etc/systemd/system/webapi.service

     

  • ​After the daemon is created, put the following lines in an editor and press Crtl+X then Y and Enter to save the file​.

    webapi.service
    Description=webapi
    After=nginx.service
    After=3CXAudioProvider01.service
    After=3CXCallFlow01.service
    After=3CXCfgServ01.service
    After=3CXEventNotificationManager.service
    After=3CXIVR01.service
    After=3CXMediaServer.service
    After=3CXPhoneSystem01.service
    After=3CXPhoneSystemMC01.service
    After=3CXQueueManager01.service
    After=3CXSystemService01.service
    After=3CXTunnel01.service
    [Service]
    Environment=DOTNET_BUNDLE_EXTRACT_BASE_DIR=/var/tmp
    WorkingDirectory=/var/www/webapi/
    ExecStart=/var/www/webapi/WebhooksApi --urls=http://127.0.0.1:8081
    Restart=always
    RestartSec=10
    SyslogIdentifier=webapi
    
    [Install]
    WantedBy=multi-user.target

     

7. Enable and Start the Daemon


  • You can use the following command to activate the daemon background service.
    Shell
    systemctl enable webapi
  • You can use below command to start daemon background service.
    Shell
    systemctl start webapi

 

8. Editing nginx.conf


Important:

This change must be made every time 3CX is updated.

  • You can open the nginx.conf file with the following commands.
    Shell
    nano /etc/nginx/sites-enabled/3cxpbx

    or

    Shell
    nano /var/lib/3cxpbx/Bin/nginx/conf/nginx.conf
  • Find this field in the opened nginx.conf file.
    nginx.conf
    client_max_body_size 300m;
    root "/var/lib/3cxpbx/Data/Http/wwwroot";
  • You need to add the following field after the field you found above.
    nginx.conf

    location ~ ^/webapi/?(.*) 

    {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8081/webapi/$1$is_args$args;
    proxy_buffering off;
    }

  • use below command to restart nginx service:

    systemctl restart nginx

 

9. Install Lame for Converting Wav Files to MP3


3CX replaces standard repositories for its own use. If lame is not installed, you need to add repository::

  • You can open the file/editor with the following command:

    Shell
    nano /etc/apt/sources.list
  • Then edit the file:

    sources.list
    deb [arch=amd64 by-hash=yes signed-by=/usr/share/keyrings/3cx-archive-keyring.gpg] http://repo.3cx.com/debian/1806 buster main
    
    deb [arch=amd64 by-hash=yes signed-by=/usr/share/keyrings/3cx-archive-keyring.gpg] http://repo.3cx.com/debian-security/1806 buster main
    
    deb http://deb.debian.org/debian buster main contrib non-free
    
    deb http://deb.debian.org/debian buster-updates main contrib non-free
    
    deb http://deb.debian.org/debian buster-backports main contrib non-free
    
    deb http://security.debian.org/debian-security/ buster/updates main contrib non-free
  • Save the file by pressing Crtl+X then Y and Enter  

  • To update;

    Shell
    apt update
  • To install Lame;

    Shell
    apt install lame
  • You can use the following commands to restart the WebAPI.

    Shell
    systemctl restart webapi
  • You can use the following command to test the status of daemon background service.

    Shell
    systemctl status 'webapi'
  • You can use this command for debug log.

    Shell
    journalctl -fu webapi

 

10. Testing webapi


After the installation is successfully completed, you can test the webapi service with the access key you created in step 4. You can perform these tests through a web browser or by using Postman.

An example API endpoint is as follows: https://{{3CXFQDN}}:{{3CXHTTPSPORT}}/webapi/{{AccessKey}}/pbx.callsinfo

Enter your 3CX server's FQDN address into the "3CXFQDN" field, enter the access key you created into the "AccessKey" field and enter the 3CX https port to "3CXHTTPSPORT" field.

Unless changed during the installation, the default HTTPS port for 3CX is 5001.

You can access the documentation on how APIs are used here.