Updated Call Control API for V20

MichaelB_3CX

3CX Team
Staff member
3CX Support
Joined
Aug 25, 2009
Messages
567
Reaction score
699

Control calls and more with the powerful .NET core API.​

With V20, we’ve updated the Call Control API for Linux - Windows to follow soon. Just like V18, it requires the application to be installed on an actual 3CX instance. A web version of this API is in the works and will be available soon.

What’s New in the Cal...​

Continue reading the Original Blog Post.

 
Last edited by a moderator:
In the article it states about the need for an actual 3CX instance. I am presuming this means that this is not supported on the 3CX hosted platform, as is the case for the Flow Designer?

Can you confirm if and when such functionality will be available for the hosted platform please
 
Are there any updates on the web version of the call control API?
 
Are there any updates on the web version of the call control API?

Based on the reverse engineering I performed on the latest version of 3CX PBX, it appears to be under construction. There's no ETA yet, but 3CX has not forgotten us; work is in progress. :-)

Breaking News:
According to the clues that @ConceptsWeb and me, we have discovered, there won't just be one new API—there will be two!

If the 3CX developers don't encounter any issues and the development projects are completed successfully, we will ultimately have one API for the WebClient and another for the CallControlAPI!

It's incredible! But of course, don't ask me for an ETA; I don't have that information.
 
Following the API documentation, when I authenticate using postman, it works correctly, but if I do it using PHP code, I get the token, but that token is not valid.
If I use the token I get in postman in my php code, it works fine, but if I use the token obtained in my php code in postman, it doesn't work either.

the problem:

If I get the token from postman, the token contains this:
....
"MaxRole": "system_owners",
....

If I get the token from php, the token contains this:
....
"MaxRole": "users",
....

being the same call, to the same url, with the same user and the same pass...

why can this happen?
 
En suivant la documentation de l'API, lorsque je m'authentifie à l'aide de postman, cela fonctionne correctement, mais si je le fais à l'aide du code PHP, j'obtiens le jeton, mais ce jeton n'est pas valide.
Si j'utilise le token que j'obtiens dans postman dans mon code php, cela fonctionne bien, mais si j'utilise le token obtenu dans mon code php dans postman, cela ne fonctionne pas non plus.

le problème:

Si je reçois le jeton du facteur, le jeton contient ceci :
....
"MaxRole": "system_owners",
....

Si j'obtiens le jeton depuis PHP, le jeton contient ceci :
....
"MaxRole": "utilisateurs",
....

étant le même appel, vers la même url, avec le même utilisateur et le même pass...

pourquoi cela peut-il arriver ?

Can you share your php code ? ( Don't forget to redact the sensitive information. )
 
Of course:

function authApi($base_uri,$username,$password){
$url = $base_uri . 'webclient/api/Login/GetAccessToken';

$data = array(
"SecurityCode" => "",
"Password" => $password,
"Username" => $username
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch);
return $result;
}
 
Your script works for me.

I added:

PHP:
echo "\nAccess Token:\n" . $result['Token']['access_token'] . "\n\n";

before
PHP:
return $result;
to display the access token.


When I use the displayed token, it works in POSTMAN or in my other scripts.
Are you possibly confusing the refresh_token with the access_token ?
 
No, I'm sure I'm using:
$result['Token']['access_token']

If you decompose the token, then the role it gives you is the correct role?

You can use: https://fusionauth.io/dev-tools/jwt-decoder
to see the token decomposition

I still get: "MaxRole": "users",
 
Same



1726552104483.png
 
Last edited:
PHP:
<?php

function authApi($base_uri,$username,$password){
$url = $base_uri . 'webclient/api/Login/GetAccessToken';

$data = array(
"SecurityCode" => "",
"Password" => $password,
"Username" => $username
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch);
echo "\nAccess Token: \n" . $result['Token']['access_token'] . "\n\n";
return $result;
}

$base_uri = 'https://MyFQDN.3cx.ca/';   // For security reasons, I prefer not to publicly share my "test" FQDN.
$username = '110';
$password = 'M0Npbx2024!!'; // My test extension password (Don't worry, I changed it before sending you this message :-) )

$result = authApi($base_uri,$username,$password);

?>
 
Ok, I think I've found the error.
In my NFR version I get the same problem as you mentioned, I get the "users" role.
In a version with paid licensing, it does work for me..

Any ideas?
 
I ran my tests again with my NFR system.

Same result.

Have you enabled 'MultiCompanyMode' on your NFR system?
Are you an owner or system owner on your NFR system?

Could it be an issue with character escaping in the password?
Are you using the same password on your NFR system and the paid system?
My PHP version is: 8.2.20

I'm just trying to point you in the right direction...

Because, on my end, everything works correctly... so I have the impression that the issue is coming from the PBX itself (but would the problem occur with Postman?).
Alternatively, the issue could be with the username or password, like a character causing problems (but wouldn't you still receive an access token?).

Is the username the extension number or the email address?


1726553701728.png
 
It's very strange
Have you enabled 'MultiCompanyMode' on your NFR system?
No.
Are you the owner or are you the owner of your NFR system?
Yes, 100%, I've tried with 2 different users, both owners of the system, putting both the ID and the email and I still have the same problem

Could it be a problem with the escaping character in the password?
It shouldn't, I've tried with simple and complex passwords.
Are you using the same password on your NFR system and the payment system?
No, but I understand that that shouldn't affect
My PHP version is: 8.2.20
My version is: PHP 8.2.22

I'm just trying to point you in the right direction...

Because on my side everything works correctly... so I have the impression that the problem comes from the switchboard itself (but would the problem occur with Postman?).
That's what I don't understand, that it works with postman, but not with php.
Alternatively, the problem could be with the username or password, like a character causing problems (but you still wouldn't get an access token?).
That's the issue, I get the token, but it's like I have other permissions, but the same code with another pbx, works fine.
It must be something with my nfr pbx.

Is the username the extension number or the email address?
As I mentioned before, I've tried both.

Additional test:
I've tried with another 3cx nfr, which has exactly the same version, and it works fine there. It's definitely something with my pbx. I'll try to set it on fire... =)


Thank you so match for your help, you really helped me a lot.
 
I've tried with another 3cx nfr, which has exactly the same version, and it works fine there. It's definitely something with my pbx. I'll try to set it on fire... =)
I doubt it will give you a better result afterward. xD

Thank you so match for your help, you really helped me a lot.
I didn’t do anything, I just tested your code. :oops:
Well, I’m glad it helped you! :D
It would be great if helping my wife with house chores were that simple! I'd just end up cleaning after she’s already cleaned everything… LOL ! xD
 
Powershell:
Code:
$tcxurl="mypbx.mydomain.de"     # needs port if not 443

$jsonauthbody = (@{
    Username="988"              # 3CX user, maybe email address
    Password="Super_Secret0815" # 3CX user password
    SecurityCode=""
} | ConvertTo-Json)

$LoginResponse = Invoke-RestMethod -Uri "https://$tcxurl/webclient/api/Login/GetAccessToken" -Body $jsonauthbody -Method POST -ContentType "application/json"

$headers = @{Authorization = "Bearer $($LoginResponse.Token.access_token)"}

# get information about endpoints
(Invoke-RestMethod -uri "https://$tcxurl/xapi/v1" -headers $headers -Method GET -ContentType "application/json").value

# or users ...
(Invoke-RestMethod -uri "https://$tcxurl/xapi/v1/Users" -headers $headers -Method GET -ContentType "application/json").value
 
Hi again...
I'm trying to make/hang up calls through the api, but I don't see any method for this in the documentation.
Is this not possible?

Thank you!
 
This is not possible with the XAPI you are using.

I suggest waiting a few more months. I reverse-engineered all versions of v20, and according to the Swagger documentation, the development of the Call Control “REST” API (ccapi) is progressing at an incredible pace. If everything goes well, I estimate it should be ready by update 4 (This is my personal estimate; I do not have official confirmation from 3CX.).

Alternatively, you could use the Call Control API (.NET Assembly), but this requires running your script locally by implementing an "agent."

https://www.3cx.com/docs/call-api-linux/

IMG_7119.jpeg

IMG_7121.jpeg

@VoIPTools are experts in this solution, having refined their tools for many years without using any “hack”. They offer a "Rest API/Relay" solution that already allows you to control calls via VoipTools' Rest API without need wait new 3CX REST API.

I hope this helps you.
 
ok, thank you very much
 
  • Like
Reactions: Guillaume Bourgeois
Hi, Can someone provide an update to the 3CX hosted service supporting API and Flow Designer?

When I log into our v20 instance, I am not seeing under Integrations anything about API and therefore not able to generate a token.

thanks
 

Forum statistics

Threads
111,955
Messages
589,925
Members
164,855
Latest member
parik24pro