Employee Time Clocks & Attendance Systems Integration - Update 3CX Status on Clock-In/Out

Status
Not open for further replies.

Florian87

Silver Partner
Basic Certified
Joined
Mar 11, 2018
Messages
21
Reaction score
29
Hello all,

I would like to share a powershell script, I just did complete. The script is reading clock-in and clock-out events from a SQL database and then is updating the 3CX status of the users to be available when clocked-in or away when clocked-out. The script is directly calling the 3CX API via HTTPS, it can be executed on any computer/server, does not have to be the 3CX machine.

Please see the full script attached. Feel free to use it on your own.

Have fun,
Florian
 

Attachments

  • Like
Reactions: edossantos
Because of all the SQL, the above script may be a bit complicated to read.

I did create a simplified example below, just to show how to use the 3CX api:


Code:
# Config Variables 3CX
$3CXURL = "https://myown3cx.my3cx.de:5001" #Please use an URL with valid SSL cert, instead of an IP-Address
$3CXUSER = "admin"
$3CXPW = "secret"


#Set HTTP headers
$http_headers = @{
"Content-Type" = "application/json;charset=UTF-8"
"Accept" = "application/json, text/plain, */*"
}
#Set TLS Version
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


#Login to 3CX and save session cookie to $session
Invoke-WebRequest "$3CXURL/api/login" -Headers $http_headers -SessionVariable 'Session' -Body "{""username"":""$3CXUSER"", ""password"":""$3CXPW""}" -Method 'POST' -UseBasicParsing


#Get Extensions / Users from 3CX
$ExtensionList = Invoke-WebRequest "$3CXURL/api/ExtensionList" -Headers $http_headers -WebSession $Session -Method 'GET' -UseBasicParsing
$ExtensionListJson = $ExtensionList.Content | ConvertFrom-Json


#search for 3CX user that has the number 210
$user = $ExtensionListJson.list | where { $_.Number -eq 210 }
#get 3CX user id
$user_id = $User.Id.ToString()


#Change 3CX status of this user to away
Invoke-WebRequest "$3CXURL/api/ExtensionList/setCurrentProfile" -Headers $http_headers -WebSession $Session -Body "{Ids: [$user_id], Value: ""Away""}" -Method 'POST' -UseBasicParsing


#Or change 3CX status of this user to available
Invoke-WebRequest "$3CXURL/api/ExtensionList/setCurrentProfile" -Headers $http_headers -WebSession $Session -Body "{Ids: [$user_id], Value: ""Available""}" -Method 'POST' -UseBasicParsing


#Logout from 3CX / End session
Invoke-WebRequest "$3CXURL/api/logout" -Headers $http_headers -WebSession $Session -Method 'POST' -UseBasicParsing
 
Thanks dude ! Amazing job ! It's exactly what i needed.
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,474
Latest member
costionofrei