3CX
Connect a self-hosted 3CX phone system to Aethex with the 3CX Configuration API and the Aethex API. Your voice agent logs in to 3CX as one of its users, answers calls to your number, and places calls through your 3CX carrier trunk.
How it works
Aethex connects to 3CX the way a desk phone does: it logs in to 3CX as a user, with that user's SIP login. 3CX then treats the agent like any other user. Calls that 3CX routes to the user reach the agent, and calls the agent places leave through your 3CX outbound rules and carrier trunk.The setup has two halves. On the 3CX side you create the user, allow the Aethex SIP edge, and route your number to the user, with the 3CX Configuration API. On the Aethex side you create a line that logs in to 3CX and give the number to your agent, with the Aethex API.Only self-hosted 3CX supports this setup. The 3CX SMB and Hosted by 3CX editions do not.
Before you start
Every 3CX call in this guide uses the 3CX Configuration API, which 3CX includes with its 8SC and higher AI license.
| What you need | Where it comes from |
|---|---|
| Self-hosted 3CX v20 on a public hostname and a fixed public IPv4 address | Your 3CX server. Aethex does not accept private addresses. |
| A 3CX API client with Configuration API access | 3CX admin console, Integrations > API > Add. Enter a Client ID, tick Enable access to the 3CX Configuration API (XAPI), set Department to System Wide and Role to System Owner or System Admin, and save. 3CX shows the API key once. |
| A carrier trunk in 3CX that receives the number the agent will use | 3CX admin console, Voice & Chat. This guide writes the number in E.164, for example +15555550100. |
| An Aethex API key and an agent | Developer portal, API keys. The key needs the sip_trunks:write, sip_trunks:read, phone_numbers:write and calls:write scopes. |
Get a 3CX access token
Exchange the Client ID and API key for an access token at POST /connect/token on your 3CX server, and send the token as a Bearer header on every Configuration API call. The token lasts 60 minutes and 3CX issues no refresh token, so request a new one when it expires. Configuration API paths start with /xapi/v1.
PBX=https://pbx.example.com
TOKEN=$(curl -s -X POST "$PBX/connect/token" \
-d client_id=aethex-setup \
-d client_secret="$THREECX_API_KEY" \
-d grant_type=client_credentials | jq -r .access_token)
# Check the token works
curl -s -G "$PBX/xapi/v1/Defs" \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode '$select=Id'Create the agent's 3CX user
Create one 3CX user for each agent. Ask 3CX for the next free extension number, then create the user with that number. Three settings in the same request matter for Aethex: PbxDeliversAudio sends the call audio through 3CX, SRTPMode set to SRTPEnabled turns on media encryption (with it off, calls connect with no audio), and AuthID set to the extension number makes the login name match the user.Then read back AuthID and AuthPassword. They are the SIP username and password Aethex logs in with in step 6.
# 1. Ask 3CX for the next free extension number
curl -s "$PBX/xapi/v1/Users/Pbx.GetFirstAvailableExtensionNumber()" \
-H "Authorization: Bearer $TOKEN"
# { "Number": "120", ... }
# 2. Create the agent's user with that number
curl -s -X POST "$PBX/xapi/v1/Users" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"Number": "120",
"FirstName": "Aethex",
"LastName": "Agent",
"AuthID": "120",
"PbxDeliversAudio": true,
"SRTPMode": "SRTPEnabled"
}'
# The response carries the new user's Id. Keep it as USER_ID.
# 3. Read the SIP login Aethex will use
curl -s -G "$PBX/xapi/v1/Users($USER_ID)" \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode '$select=Number,AuthID,AuthPassword'Allow the Aethex SIP edge
3CX blocks an address after repeated failed logins. Add the two Aethex SIP edge addresses to the 3CX IP blocklist as Allow entries, so a failed login during setup does not get Aethex blocked. This is the API equivalent of Advanced > IP Blacklist in the admin console.
for ip in 13.63.135.167 51.21.123.34; do
curl -s -X POST "$PBX/xapi/v1/Blocklist" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{ \"IPAddrMask\": \"$ip\", \"BlockType\": \"Allow\", \"Description\": \"Aethex SIP edge\" }"
doneRoute your number to the agent
Calls to your number arrive on your carrier trunk. Add an inbound rule that sends calls for that number to the agent's user, in and out of office hours. List your trunks first: put the trunk's Number in TrunkDN, and the number exactly as DidNumbers shows it in Data. Replace 120 with the extension number from step 2.
# Find the carrier trunk and the number as 3CX stores it
curl -s -G "$PBX/xapi/v1/Trunks" \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode '$select=Id,Number,DidNumbers'
# Send calls for that number to the agent's user, at all hours
curl -s -X POST "$PBX/xapi/v1/InboundRules" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"RuleName": "Aethex agent",
"Condition": "BasedOnDID",
"Data": "15555550100",
"TrunkDN": { "Number": "10000" },
"OfficeHoursDestination": { "To": "Extension", "Number": "120" },
"OutOfOfficeHoursDestination": { "To": "Extension", "Number": "120" }
}'Let the agent call out
Add an outbound rule for the agent's extension, with no prefix and no number-length limit, and route it to your carrier trunk by the trunk's Id. Caller ID defaults to the trunk's number.3CX uses the first rule that matches. If an earlier rule already covers the extension, either add the extension to that rule's DNRanges with PATCH /xapi/v1/OutboundRules(id), or move the new rule up with POST /xapi/v1/OutboundRules/Pbx.MoveUpDown.
GET /xapi/v1/CountryCodes, add their country codes, and send the whole list back with PATCH /xapi/v1/CountryCodes.curl -s -X POST "$PBX/xapi/v1/OutboundRules" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"Name": "Aethex agent",
"DNRanges": [{ "From": "120", "To": "120" }],
"Routes": [{ "TrunkId": 1 }]
}'
# Check the order: 3CX uses the first rule that matches the extension
curl -s -G "$PBX/xapi/v1/OutboundRules" \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode '$select=Id,Name,Priority,DNRanges'Create the Aethex line
Create a line in register mode. Aethex logs in to 3CX with the user's login and keeps the login active, so 3CX can send calls to the agent and accept calls from it. The response carries the line's id; keep it for steps 7 and 8. The table explains each value.
| Field | Value for 3CX |
|---|---|
auth_mode | register: Aethex logs in to 3CX like a desk phone. Valid only with type set to inbound; Aethex adds the outbound side itself. |
numbers | Your number in E.164. A register line serves exactly one number, so create one line per number. |
outbound_address | Your 3CX hostname and SIP port, usually 5060. |
realm | 3CXPhoneSystem. 3CX answers the login challenge for this realm, not for its hostname. Without it the line stays at failing. |
auth_username, auth_password | AuthID and AuthPassword from step 2. The password is stored encrypted and never returned. |
allowed_addresses | Your 3CX public IPv4 address, as the only entry. It opens the Aethex firewall to your 3CX. |
transport | udp or tcp. Register lines do not support TLS. |
outbound_dial_format | digits: Aethex sends the number without the leading +. 3CX changes a number that starts with +, and the call then fails with "Number not found". |
outbound_from_user | username: outbound calls carry the login name as the SIP From user, which is how 3CX matches the call to the agent's user. The number travels in P-Asserted-Identity. With the default, number, 3CX refuses the agent's calls as an unidentified incoming call. |
name, numbers, allowed_addresses, outbound_dial_format, the call limits and status. To change the 3CX address, realm, login, transport, media encryption or outbound_from_user, delete the line and create a new one.curl -X POST https://api.aethexai.com/api/v1/sip-trunks \
-H "X-API-Key: $AETHEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "3CX agent line",
"type": "inbound",
"auth_mode": "register",
"numbers": ["+15555550100"],
"outbound_address": "pbx.example.com:5060",
"realm": "3CXPhoneSystem",
"auth_username": "120",
"auth_password": "<AuthPassword from step 2>",
"allowed_addresses": ["203.0.113.10"],
"transport": "udp",
"outbound_dial_format": "digits",
"outbound_from_user": "username"
}'Give the number to your agent
Register the number against the line and the agent. agent_id makes the agent answer calls to the number. Set outbound_enabled to true: a register line places calls through this link between the number and the line.
curl -X POST https://api.aethexai.com/api/v1/phone-numbers/sip/register \
-H "X-API-Key: $AETHEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone_number": "+15555550100",
"trunk_id": "<id returned in step 6>",
"agent_id": "<your-agent-id>",
"outbound_enabled": true
}'Check the login and test calls
Within about a minute of creating the line, Aethex logs in to 3CX. GET /sip-trunks/:id then returns registration_status as registered, and 3CX returns the user with IsRegistered set to true. If the line shows failing, see Troubleshooting below.To test inbound, call your number from a phone outside 3CX. The agent answers, and the call appears in 3CX Reports and in your Aethex call log. To test outbound, trigger a call with your number as from_number. The phone rings, the agent speaks when it is answered, and 3CX reports the call as outbound.
# Aethex: the line logs in to 3CX within about a minute
curl -s https://api.aethexai.com/api/v1/sip-trunks/$TRUNK_ID \
-H "X-API-Key: $AETHEX_API_KEY" | jq .registration_status
# "registered"
# 3CX: the agent's user shows as registered
curl -s -G "$PBX/xapi/v1/Users($USER_ID)" \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode '$select=Number,IsRegistered'
# Outbound: the agent calls a phone through 3CX
curl -X POST https://api.aethexai.com/api/v1/calls/trigger \
-H "X-API-Key: $AETHEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "<your-agent-id>",
"to_number": "+15555550199",
"from_number": "+15555550100"
}'Network and firewall
Open these ports between your 3CX and the Aethex SIP edge (sip.aethexai.com, at the addresses in step 3). Audio uses G.711 A-law (PCMA) or mu-law (PCMU). Your 3CX media port range is under Ports > Media in the 3CX dashboard.
| Direction | Signalling | Media (RTP) |
|---|---|---|
| Aethex to 3CX | TCP, UDP 5060 | UDP 9000–10999 (3CX default) |
| 3CX to Aethex | TCP, UDP 5060 | UDP 10000–60000 |
Troubleshooting
The problems seen most often, what causes them, and the fix.
| Symptom | Cause | Fix |
|---|---|---|
Line stays at failing, and the 3CX Event Log shows "Block WAN requests is ON" | Block remote non-tunnel connections is still on for the user. | Uncheck it on the user's Options tab in the admin console (step 2). |
Line stays at failing | Wrong realm, login or password. | Create the line again with realm set to 3CXPhoneSystem and the AuthID and AuthPassword from step 2. |
| Callers reach voicemail | Aethex is not logged in as the agent's user. | Check that the line shows registered and the 3CX user shows IsRegistered (step 8). |
| Calls connect with no audio | SRTP is off for the user, or the media ports are closed. | Set SRTPMode to SRTPEnabled (step 2) and open the ports in Network and firewall. |
| Outbound calls fail, and the 3CX Event Log shows "Unidentified Incoming Call" | The line sends the number as the caller instead of the login name. | Create the line again with outbound_from_user set to username. |
| Outbound calls fail with "Number not found" | The number was sent with a leading +. | Set outbound_dial_format to digits with PATCH /sip-trunks/:id. |
| Outbound calls fail with no matching outbound rule | No outbound rule covers the agent's extension, or an earlier rule matches first. | Add the extension to a rule that routes to your carrier trunk (step 5). |
