> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bland.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 3CX

> Connect a 3CX phone system to a Bland agent over SIP, and transfer callers back to 3CX extensions with SIP REFER

Send calls from your 3CX phone system to a Bland agent, and let the agent transfer callers back to your 3CX extensions, queues, and ring groups. 3CX connects to Bland as a SIP trunk over TLS, with SRTP media.

## What works

* Calls from 3CX to your agent
* Outbound calls from your agent through 3CX
* Transfers back to 3CX extensions, with SIP REFER
* The original caller ID, passed to the agent in SIP headers

## Prerequisites

* 3CX version 20, reachable from the internet on a fully qualified domain name (FQDN), for example `yourcompany.3cx.com`
* Admin access to the 3CX Management Console
* A Bland account with SIP trunking enabled. If there is no **SIP** tab under **Phone numbers**, contact Bland support

## Configure 3CX

**1. Add a SIP trunk for Bland**

In the 3CX Management Console, go to **Voice & Chat** and add a SIP trunk. Set the server to your Bland region, for example `us2.sip.bland.ai`, port `5061`, transport TLS. The other regions are under [Connection endpoints](https://docs.bland.ai/agents/sip-network.md#connection-endpoints).

Use IP-based authentication, with no registration. If 3CX asks for a main trunk number, enter one of the numbers you will route to Bland.

**2. Set encryption and codecs**

Set call encryption (SRTP) to **Mandatory**. Bland rejects calls offered with plain RTP.

Put G.711 first in the codec list: PCMA (A-law) outside North America, PCMU (μ-law) in North America. Leave direct media off, so audio flows through 3CX.

**3. Check the public IP**

In 3CX's network settings, make sure 3CX advertises its real public IP. If automatic detection picks the wrong one, set it by hand. A wrong public IP is the most common cause of one-way or silent calls.

**4. Allow Bland on your firewall**

Allow TLS on port 5061 and SRTP on UDP 16384 to 32768 from all six of Bland's IPs for your region.

**5. Route calls to Bland**

Send the calls the agent should answer to the Bland trunk. For example, forward a DID, an IVR option, or a queue overflow to a number on the Bland trunk, with an outbound rule that picks the Bland trunk for that number.

## Configure Bland

**1. Open the setup wizard**

At **All agents**, go to **Dispatch**, then **Phone numbers**, then the **SIP** tab, and press **Create trunk**.

**2. Provider**

Pick **3CX** and enter your 3CX FQDN, for example `yourcompany.3cx.com`. Add a port only if 3CX listens for TLS on a port other than 5061.

**3. Firewall**

Confirm you allow-listed Bland's IPs, and continue.

**4. Authentication**

Pick **IP-based** and press **Create trunk**.

**5. Numbers**

Add the numbers 3CX sends to Bland, in E.164 format, for example `+61370000000`.

**6. Assign an agent**

Under **Phone numbers**, press **Configure** on the number and pick the agent under **Assignment**.

You know it worked when a call forwarded from 3CX reaches the agent and shows up on the trunk's **Overview** tab.

## Transfer callers back to 3CX

Use SIP REFER. 3CX resolves the extension, rings it, and Bland leaves the call.

In the agent's **Transfer Call** node, turn on **Allow SIP/DID targets** and **Hand off via SIP REFER**. Enter the target as a SIP URI with the extension number:

```text theme={null}
sip:1018@yourcompany.3cx.com
```

Use the extension, queue, or ring group number 3CX knows internally, not a phone number. 3CX's dial plan doesn't map an E.164 target back to an extension.

> [!NOTE]
>
> Use REFER rather than a new INVITE with 3CX. 3CX identifies a trunk by the IP a call comes from, and silently drops a new INVITE from an address it doesn't map to the Bland trunk. A REFER travels inside the call 3CX already accepted. See [Transfers](https://docs.bland.ai/agents/sip-transfers.md) for every transfer method.

## Caller ID

When 3CX forwards a call to Bland, it sends the original caller in the `P-Asserted-Identity`, `Remote-Party-ID`, and `Diversion` headers. Your agent reads them as `{{sip_header_x-original-pai}}`, `{{sip_header_x-original-rpid}}`, and `{{sip_header_x-original-diversion}}`. See [SIP headers](https://docs.bland.ai/agents/sip-headers.md). A value of `anonymous` means the caller withheld their number.

To keep the original caller in the `From` header too, set these outbound parameters on the Bland trunk in 3CX:

* **From: User Part**: `OriginatorCallerID`
* **From: Display Name**: `OriginatorCallerDisplayName`

This doesn't apply to calls forwarded through a ring group, because the ring group places a new call.

## Common failures

> [accordion] Calls connect with one-way or no audio
>
> 3CX advertises the wrong public IP, or the RTP range is blocked. Set the public IP by hand, and allow UDP 16384 to 32768 to and from Bland's media IPs.

> [accordion] Calls are rejected with 488 Not Acceptable Here
>
> SRTP isn't on. Set call encryption to **Mandatory** on the Bland trunk in 3CX.

> [accordion] Calls are challenged with 407 Proxy Authentication Required
>
> Bland doesn't recognize your 3CX's IP. Check the trunk in Bland uses **IP-based** authentication, and contact Bland support if your public IP changed.

> [accordion] The TLS connection to Bland fails
>
> Use port 5061 with TLS, and make sure 3CX trusts the Let's Encrypt ISRG Root X1 CA.

> [accordion] A transfer rings nothing, and 3CX never responds
>
> The transfer used a new INVITE from an IP 3CX doesn't map to the trunk. Turn on **Hand off via SIP REFER**.

> [accordion] A REFER to a phone number fails
>
> 3CX can't route an E.164 target to an internal extension. Use the extension in the SIP URI, for example `sip:1018@yourcompany.3cx.com`.

> [accordion] The call ended on the phone but stays live in Bland
>
> The `BYE` didn't reach Bland. Check nothing between 3CX and Bland closes the TLS connection early, and share the call's SIP trace with Bland support. 3CX's own packet capture helps compare both sides.

## Next steps

> [card] [Transfers](https://docs.bland.ai/agents/sip-transfers.md)
>
> REFER, new INVITE, and warm transfers.

> [card] [Network and security](https://docs.bland.ai/agents/sip-network.md)
>
> Bland's regions, IPs, and TLS and SRTP.

Docs for agents: [llms.txt](https://docs.bland.ai/llms.txt)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.