Help getting the API token on v20 Build 1620

Status
Not open for further replies.

Paul-2024

Customer
Joined
Feb 16, 2024
Messages
48
Reaction score
12
We have an in-house CRM and I would like to be able to use the API for a few reasons, I learned the endpoint
is https://mycompanyname.3cx.us/xapi/v1, but I don't know how to get started with authentication since in my
dashboard (I'm the owner) there is no API/Token setting.

I checked https://mycompanyname.3cx.us/xapi/v1/swagger.yaml and it seems to respond but can't do anything
on it without auth.

Can someone please help me out on this one?
Thanks
 
The API isn't officially released, that's why no place to generate a key or any documentation. I'm not sure how much 3CX sanctioned advice you'll find here.
 
  • Like
Reactions: Evolute IT
The API isn't officially released, that's why no place to generate a key or any documentation. I'm not sure how much 3CX sanctioned advice you'll find here.
Damn, we have an in-house CRM and we chose to switch from our previous PABX to 3CX mostly because it had an API that we could leverage in our system (downloading reports, recording, etc, etc).

So basically version 20 was stripped away completely from the API for now, I mean temporarily? Will they ever add it back?
 
Damn, we have an in-house CRM and we chose to switch from our previous PABX to 3CX mostly because it had an API that we could leverage in our system (downloading reports, recording, etc, etc).

So basically version 20 was stripped away completely from the API for now, I mean temporarily? Will they ever add it back?
Other then the call control API (which is not the same as what you linked), 3CX has never had a public API.

The API you linked has been in use for some time (v18, possibly v16), but never official nor with any documentation. That doesn't mean you can't use it, but it means that you're going to have to walk through it on your own/not with official support and 3CX might shutdown any discussion that takes place on their forums.

3CX has stated they will release a public API in v20 and in v18 they did release a webmeeting API, so maybe in some time it will be official.

Again, so that I'm clear
1. Never has the xapi linked been for public use - it's how 3CX talks to 3CX internally.
3. It's used on v18 or v20.
4. It's not officially for public use. hence no documentation or settings that are visible
7. I have heard that some people use it already, but it's not highly discussed on official forums
9. It might become an official API released publicly in the near future.
 
  • Like
Reactions: Evolute IT
Other then the call control API (which is not the same as what you linked), 3CX has never had a public API.

The API you linked has been in use for some time (v18, possibly v16), but never official nor with any documentation. That doesn't mean you can't use it, but it means that you're going to have to walk through it on your own/not with official support and 3CX might shutdown any discussion that takes place on their forums.

3CX has stated they will release a public API in v20 and in v18 they did release a webmeeting API, so maybe in some time it will be official.

Again, so that I'm clear
1. Never has the xapi linked been for public use - it's how 3CX talks to 3CX internally.
3. It's used on v18 or v20.
4. It's not officially for public use. hence no documentation or settings that are visible
7. I have heard that some people use it already, but it's not highly discussed on official forums
9. It might become an official API released publicly in the near future.
Gotcha, I'm ok using the call control API as long as I'm able to query active calls on it but still I can't find resources and documentation and I'm wondering if that can be used without a token to since I can't generate one, do you have any documentation to share?
 
Dealing with this surprise currently since I upgraded from v18 to v20 and didn't realise the API had changed.

If you log into 3CX on Chrome and open developer tools, the Network tab shows you the API calls made on login. Make sure to tick "Preserve log" at the top otherwise the logs will disappear on redirect. You can right-click on each API call and choose Copy->Copy as cURL or "Copy as fetch" to show the parameters used in the HTTP request. It looks like it calls "GetAccessToken" to get the access_token used as bearer auth in subsequent calls. Haven't yet tried this programatically though!
 
Be aware that playing with undocumented APIs can cause significant problems if not used properly.

If you don't know what you're doing with these APIs, then don't mess with them.
 
Dealing with this surprise currently since I upgraded from v18 to v20 and didn't realise the API had changed.

If you log into 3CX on Chrome and open developer tools, the Network tab shows you the API calls made on login. Make sure to tick "Preserve log" at the top otherwise the logs will disappear on redirect. You can right-click on each API call and choose Copy->Copy as cURL or "Copy as fetch" to show the parameters used in the HTTP request. It looks like it calls "GetAccessToken" to get the access_token used as bearer auth in subsequent calls. Haven't yet tried this programatically though!
So whatever you were using on the v18 API is gone from v20? I mean the "classic" call control AP everyone mentions is no longer available?
 
So whatever you were using on the v18 API is gone from v20? I mean the "classic" call control AP everyone mentions is no longer available?
I was just using the v18 CallLog endpoint to extract call data and load it into my analytics database, so can't speak about the other functionality. From the Swagger though, it appears I have a much better option now under the v20 ReportCallLogData endpoint.
 
I was just using the v18 CallLog endpoint to extract call data and load it into my analytics database, so can't speak about the other functionality. From the Swagger though, it appears I have a much better option now under the v20 ReportCallLogData endpoint.

Are you using v20 hosted by 3CX with v18 CallLog endpoint?

So, I was able to get a bearer token and started playing with the v20 API using postman, a lot of things are working perfectly fine however ReportCallLogData returns 404, so far it's the only endpoint with that status code, all others are working fine and I can get all types of information from out installation, but I was looking precisely to get a list of active calls and was hoping ReportCallLogData would have it.
 
Are you using v20 hosted by 3CX with v18 CallLog endpoint?
No, with the new ReportCallLogData endpoint. I'm not getting a 404 when I run it. Doing a GET using the endpoint in the Swagger where {{baseUrl}} is "/xapi/v1" and it's working fine.
 
No, with the new ReportCallLogData endpoint. I'm not getting a 404 when I run it. Doing a GET using the endpoint in the Swagger where {{baseUrl}} is "/xapi/v1" and it's working fine.
Strange, could you share or compare your request with mine?

Simplified:

curl --location 'https://mydomain.3cx.us/xapi/v1/ReportCallLogData' \
--header 'Authorization: Bearer BEARER_CODE

All params:
curl --location 'https://mydomain.3cx.us/xapi/v1/ReportCallLogData?periodFrom=2023-01-01T00:00:00Z&periodTo=2023-02-01T00:00:00Z&sourceType=1&sourceFilter=filter&destinationType=2&destinationFilter=filter&callsType=3&callTimeFilterType=4&callTimeFilterFrom=2023-01-01T00:00:00Z&callTimeFilterTo=2023-02-01T00:00:00Z&hidePcalls=false'

This also results in a 404:
/ReportCallLogData/Pbx.DownloadCallLog

On the other hand I can call CallHistoryView and other endpoints no problem.
 
Ah yeah it's a tricky one, not sure why they've designed it like this, but the endpoint is actually:

Code:
https://mydomain.3cx.us/xapi/v1/ReportCallLogData/Pbx.GetCallLogData(periodFrom={{periodFrom}},periodTo={{periodTo}},sourceType={{sourceType}},sourceFilter={{sourceFilter}},destinationType={{destinationType}},destinationFilter={{destinationFilter}},callsType={{callsType}},callTimeFilterType={{callTimeFilterType}},callTimeFilterFrom={{callTimeFilterFrom}},callTimeFilterTo={{callTimeFilterTo}},hidePcalls={{hidePcalls}})

So all those "parameters" such as periodFrom aren't actually GET parameters, they're part of the endpoint address (and you need to replace the parts in the curly brackets with the actual values). It's only when you get to $top and $skip and so on that these are actually parameters. If you look at the request in Chrome Devtools you'll be able to see exactly how it's done.
 
  • Like
Reactions: Evolute IT
Ah yeah it's a tricky one, not sure why they've designed it like this, but the endpoint is actually:

Code:
https://mydomain.3cx.us/xapi/v1/ReportCallLogData/Pbx.GetCallLogData(periodFrom={{periodFrom}},periodTo={{periodTo}},sourceType={{sourceType}},sourceFilter={{sourceFilter}},destinationType={{destinationType}},destinationFilter={{destinationFilter}},callsType={{callsType}},callTimeFilterType={{callTimeFilterType}},callTimeFilterFrom={{callTimeFilterFrom}},callTimeFilterTo={{callTimeFilterTo}},hidePcalls={{hidePcalls}})

So all those "parameters" such as periodFrom aren't actually GET parameters, they're part of the endpoint address (and you need to replace the parts in the curly brackets with the actual values). It's only when you get to $top and $skip and so on that these are actually parameters. If you look at the request in Chrome Devtools you'll be able to see exactly how it's done.
OpenAPI specs, it's a function and not an entity. That's why.
 
OpenAPI specs, it's a function and not an entity. That's why.
Gotcha. I expect they'll make it more "REST-like" when they release the v20 REST API publically.
 
Gotcha. I expect they'll make it more "REST-like" when they release the v20 REST API publically.
Probably not. The XAPI is basically the configuration API that's coming, and they warned people in their blog that it's gonna need skilled programmers to use it.
 
Are you using v20 hosted by 3CX with v18 CallLog endpoint?

So, I was able to get a bearer token and started playing with the v20 API using postman, a lot of things are working perfectly fine however ReportCallLogData returns 404, so far it's the only endpoint with that status code, all others are working fine and I can get all types of information from out installation, but I was looking precisely to get a list of active calls and was hoping ReportCallLogData would have it.
Are you willing to share how you obtained the token?
 
Are you willing to share how you obtained the token?
Absolutely.

Method: POST
Url: https://yourdomain.3cx.us/webclient/api/Login/GetAccessToken
Body:
JSON:
{"SecurityCode":"","Password":"{{Password}}","Username":"{{User}}"}

Response: 200 OK

JSON:
{
    "Status": "AuthSuccess",
    "Token": {
        "token_type": "Bearer",
        "expires_in": 60,
        "access_token": "ACCESS_TOKEN_HERE",
        "refresh_token": "REFRESH_TOKEN_HERE"
    },
    "TwoFactorAuth": null
}

The token has an expiration date so has to be renewed every 60 minutes.

Tip, if you use Postman you can store the token in a variable to be used in other requests by using this code in the "Tests" tab of the request that queries the token:

JavaScript:
var jsonData = pm.response.json();
pm.collectionVariables.set("Token", jsonData.Token.access_token);
 
do you know what hidePcalls is used for?
 
Status
Not open for further replies.

Latest Posts

Members Online Now

Forum statistics

Threads
111,845
Messages
589,333
Members
164,681
Latest member
JV J