import requests
import json
# Fill these 3 lines with real information
serverFQDN = "{FQDN}:{port}"
userName = "{owner}"
passWord = "{password}"
# Authenticate on 3CX server with Username and Password to get an Access Token
# POST /webclient/api/Login/GetAccessToken
url = "https://" + serverFQDN + "/webclient/api/Login/GetAccessToken"
headers = {"Content-Type": "application/json; charset=utf-8"}
data = {"SecurityCode":"", "Username":userName, "Password":passWord}
response = requests.post(url, headers=headers, json=data)
access_token = response.json() ['Token']['access_token']
#print ("access_token ", access_token)
# Nah, it's all good
# Get first connection with 3CX server, request version
# GET /xapi/v1/Defs?%24select=Id
url = "https://" + serverFQDN + "/xapi/v1/Defs?%24select=Id"
headers = {"Content-Type": "application/json; charset=utf-8", 'Authorization': 'Bearer ' + access_token}
data = {}
response = requests.get(url, headers=headers, json=data)
#print (response.json())
# Who cares realy?
# Create new Extension on the 3CX Server
# POST /xapi/v1/Users
url = "https://" + serverFQDN + "/xapi/v1/Users"
headers = {"Content-Type": "application/json; charset=utf-8", 'Authorization': 'Bearer ' + access_token}
data = {
"AccessPassword": "QrzxYQwa5!",
"EmailAddress": "[email protected]",
"FirstName": "TestFirstName",
"Id": 0,
"Language": "EN",
"LastName": "TestLastName",
"Number": "211",
"PromptSet": "1e6ed594-af95-4bb4-af56-b957ac87d6d7",
"SendEmailMissedCalls": True,
"VMEmailOptions": "Notification",
"Require2FA": True
}
# Here we go...
response = requests.post(url, headers=headers, json=data)
print (response.json())
# Okay, it's done!