Programmatically (SSH or REST-API) Get User details

Status
Not open for further replies.

Sparky Bear

Silver Partner
Basic Certified
Joined
Mar 4, 2022
Messages
109
Reaction score
115
Good day everyone,

In V18 we would runa weekly extension statistic report as CSV then use powershell to sort and cleanup the results before passing the list of extensions to accounts,
In V20 this is not possible,

is there any way I can get a list of all extensions (and display names) so I can use this data outside 3CX?


Best regards,

Benjamin Allott,
 
/xapi/v1/Users
 
Good day everyone,

In V18 we would runa weekly extension statistic report as CSV then use powershell to sort and cleanup the results before passing the list of extensions to accounts,
In V20 this is not possible,

is there any way I can get a list of all extensions (and display names) so I can use this data outside 3CX?


Best regards,

Benjamin Allott,
2023-08-09_20-08-19.png


If this is what you need, then download and try it for free
https://creomate.com/3cx-grafana

And REST API method e.g.https://{{3CXFQDN}}/webapi/{{AccessKey}}/ext.state.get?num=100
{
"num": "100",
"registered": true,
"status": "Free",
"fwdName": "Available",
"qGlobalStatus": true,
"qStatus": [
{
"num": "800",
"status": true
}
]
}
 
unfortunately, neither of these help,
I don't want to pay for even more external addon's and I am unsure how /xapi/v1/Users is meant to work
 
so I finally had time to look at this again,
I can see that /xapi/v1/users/Pbx.ExportExtensions() is probably exactly what I need from swagger,
I am using PowerShell and have no idea how to get the access token, been trying to force it from some Cisco examples using invoke-restmethod or invoke-webrequest,

I can see that it is a post method using FQDN/webclient/api/Login/GetAccessToken
but all I get is 400 bad request or 405 method not allowed

any assistance on just authenticating would be amazing, hell even SSH into the backend and reading a file would work, I just need the EXT number and first/last name
 
okay so update, I got it working, this is all in PowerShell

A bit of trial and error but here we go documenting as much as I can for the next victim to try this

I am a bit skeptical of the security and as such this should probably be run locally but hey, it works remote, just do it over a VPN to stay secure (No liability or guarantee is promised and 3CX may change the API keys)

first of all, we have a username and password (if you have a way of pulling a 2fa code then congrats
so lets build the 1st request so we can get our token

Code:
$AuthBody = @{
    Password="ENTER PASSWORD HERE"
    SecurityCode=""
    Username="[email protected]"
}
$jsonauthbody = $authbody |ConvertTo-Json

the next part is to POST the request to get the auth token,
This is in a body to pass the credentials along

Code:
$LoginResponse = Invoke-RestMethod -Uri "https://mycompany.3cx.school/webclient/api/Login/GetAccessToken" -Body $jsonauthbody -Method POST -ContentType "application/json"

This will return an access key,
Next we need to build the header so we can authorize our access
Code:
$accesstoken =  $LoginResponse.Token.access_token
$Headers = @{
    Authorization = "Bearer $accesstoken"
}

lastly we can run out command

Code:
Invoke-RestMethod -uri "https://mycompany.3cx.school/xapi/v1/Users -headers $headers -Method GET -ContentType "application/json"

you can add additional tags to the end of the URL to filter example

Code:
Invoke-RestMethod -uri"https://mycompany.3cx.school/xapi/v1/Users?%24filter=not%20startsWith(Number%2C%27HD%27)&%24count=true&%24orderby=Number&%24select=Id%2CDisplayName%2CEmailAddress%2CNumber" -headers $headers -Method GET -ContentType "application/json"
 
Last thing to add regarding V20 API's

https://mycompany.3cx.school/xapi/v1/swagger.yaml is a very useful resource as well as F12,

Until there is a supported public API available

and again "disclaimer disclaimer blah blah own risk, don't test on prod"

Please don't ask how long this took me to figure out (or how much more time I need to invest still)
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
111,948
Messages
589,880
Members
164,841
Latest member
erre