Today we had another job of a special kind. Due to data protection regulations, certain settings had to be changed for all users on our 3CX system. In version 18 of 3CX, there was a mass data change in the web interface. Unfortunately, this is completely missing in version 20. It can't be that someone of my team have to configure every user manually via the web interface. After some research on the Internet, I came across 3CX Configuration API

Not really good because they offer a incomplete Postman Collection (Windows), but with some experience in using API's i were able to solve the problem. To make it easier for you, here are the necessary steps to do it with curl instead of postman (freemium).

Authentication against the API

As we do not have a multi-company system, we use the user token method. First, go to your 3CX Phone System / Admin Console / Users. Create a user of any preferred role, e.g System Owner, ensure the "Enable 2FA" option is unticked and give it a preferred email address. Reset password for this user via the welcome email reset link that was just sent.

To obtain the User token we should call the API. We do this with a simple curl:

please change {FQDN_of_your_3cx}, {yourpass} and {yourapiuser} so that it fit to your setup.

I piped the output of curl to jq so that it looks nicer.

curl -s -X POST https://{FQDN_of_your_3cx}/webclient/api/Login/GetAccessToken \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"SecurityCode":"","Password":"{yourpass}","Username":"{yourapiuser}"}' | jq '.'

When successful this will issue an Access token and a Refresh token.

token

Store the token

So that the token is not visible as plain text in the curl command, I have stored the content of the access_token field in /tmp/token. I refer to this file in the following curl commands.

Change the needed params

At the end of the documentation linked above, all endpoints and values are linked in a yaml. here is the direct link to the yaml:https://downloads-global.3cx.com/downloads/misc/restapi/3cxconfigurationapi.yaml

with this Informations we build the Patch and send it via curl to the API:

#!/bin/bash
# Update 3CX Userconfig via 3CX Configuration API by ♞ Raffael.Willems@im-c.de
for i in {1..774}
do
curl -X PATCH -H "Authorization: Bearer $(cat /tmp/token)" https://{FQDN_of_your_3cx/xapi/v1/Users\($i\) \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"AllowOwnRecordings": false,"VMEmailOptions": "Attachment","VMDisablePinAuth": true,"PromptSet": "8210986B-9412-497f-AD77-3A554F4A9BDB"}'
done

The bash script iterates over all existing users and changes the corresponding settings, which are as follows:

  • AllowOwnRecordings will be set to false
  • VMEmailOptions will be set to Attachment. This setting causes the voicemail to send an e-mail with the corresponding voicemail message as Attachment
  • PromptSet sets the Voicemail Prompts to English. If another Promptset is needed you can set the needed Promptset on a User and call the Get User API Endpoint to get the correct Value for that Promptset. (curl -X GET -H "Authorization: Bearer $(cat /tmp/token)" https://{FQDN_of_your_3cx}/xapi/v1/Users\(36\) | jq '.')

After Running the Bashscript the Job is DONE 🤓

4608224-3067817031

Previous Post Next Post