Home ›Support ›Knowledge-Base ›Incoming Call Webhook Guide

Route Incoming Calls with a Webhook

With the Incoming Call Webhook, your server is told about each call to your number and decides where it goes — by caller, time of day, CRM data or any other logic. You then set the number’s destination through the API, and the call is connected.

How It Works

What happens when someone calls a number set to Incoming Call Webhook.

1

The call arrives and the caller hears ringing

The caller hears ringing until the call is routed.

2

PBXme posts the call data to your webhook

The call details are sent to your webhook URL as a JSON POST request (fields below).

3

Your server confirms within 5 seconds

Respond with HTTP 200. If no confirmation arrives within 5 seconds, PBXme retries — up to 5 attempts, 5 seconds apart, all with the same call_id. If every attempt fails, the call is dropped.

4

Your server sets the destination via the API

Call DID Forward Setting to set the number’s destination for this caller — for example a PSTN number, a SIP device or a SIP trunk (see the forwarding types). This must happen within 30 seconds of the call arriving; otherwise the call is dropped.

5

The call is connected

The new forwarding is applied within about a second, the destination rings, and the caller is connected.

Important: the destination you set in step 4 is saved as the number’s forwarding, so following calls go to that destination until you change it. After the call it is your choice — keep it, set another destination, or set the number back to Incoming Call Webhook (call_type "19") so your webhook handles the next call.

What Your Webhook Receives

{
  "call_id": "265fff9c-e4ca-4d54-8de9-8caff0f95444",
  "call_timestamp": "2026-12-02 15:25:02",
  "caller_id": "0523609233",
  "dialed_did": "972737004333",
  "did_id": "14229"
}
FieldMeaning
call_idUnique ID of the call — the same on every retry, so you can ignore duplicates
call_timestampTime the call arrived, in UTC
caller_idThe caller’s number, in the format the carrier delivered it
dialed_didYour number that was called, in international format
did_idThe number’s ID — use it directly as did_id in DID Forward Setting
Security: requests come from our call servers at 195.201.136.88 and 95.217.164.101 and carry no signature. Allow only these source IPs on your webhook endpoint and use HTTPS.

Step 1: Prepare Your Webhook

A publicly reachable HTTPS endpoint that accepts POST requests.

1

Create the endpoint

Set up a URL on your server, for example https://example.com/pbxme/incoming-call. Respond with HTTP 200 immediately, then decide the destination in the background and set it through the API — slow lookups must never delay the 200.

// Node.js 18+ / Express — Incoming Call Webhook receiver
// Production notes:
// - Run behind HTTPS. Allow only the platform's webhook IPs at your firewall or
//   reverse proxy as well; the check below assumes the proxy sets X-Forwarded-For.
// - The duplicate filter here is in memory, for one process. With several
//   processes or servers, use a shared store (for example Redis SET NX with a TTL).
const express = require("express");
const app = express();
app.set("trust proxy", "loopback");   // trust only your own reverse proxy
app.use(express.json());

const BASE = "https://newsip.pbxme.com";
const HEADERS = { "x-auth-token": "YOUR_API_KEY", "Content-Type": "application/json" };
const WEBHOOK_IPS = new Set(["195.201.136.88", "95.217.164.101"]);
const ROUTE_DEADLINE_MS = 30000;      // the destination must be set within 30 s
const SEEN_TTL_MS = 10 * 60 * 1000;   // remember call_ids for 10 minutes
const seen = new Map();               // call_id -> { state, at }

// Log in once and reuse the token; log in again when it is rejected.
let session = null;
async function login() {
  const res = await fetch(`${BASE}/api/login/`, {
    method: "POST", headers: HEADERS,
    body: JSON.stringify({ username: "YOUR_ACCOUNT_NUMBER", password: "YOUR_PASSWORD" }),
    signal: AbortSignal.timeout(10000)
  });
  const auth = await res.json();
  if (!res.ok || !auth.id || !auth.account_token) throw new Error("Login failed: " + JSON.stringify(auth));
  session = { id: auth.id, token: auth.account_token };
  return session;
}

// DID Forward Setting; checks both the HTTP status and the API result.
async function forward(didId, callType, value, deadline) {
  for (let attempt = 0; attempt < 2; attempt++) {
    const { id, token } = session || await login();
    const msLeft = deadline - Date.now();
    if (msLeft <= 0) throw new Error("Routing deadline passed");
    const res = await fetch(`${BASE}/customer/did_management/`, {
      method: "POST", headers: HEADERS, signal: AbortSignal.timeout(msLeft),
      body: JSON.stringify({
        action: "forward", did_id: didId, call_type: callType, call_type_value: value,
        always: "5", user_busy: "5", user_not_registered: "5", no_answer: "5",
        extensions: "", call_type_vm_flag: "", always_destination: "", always_vm_flag: "",
        user_busy_destination: "", user_busy_vm_flag: "",
        user_not_registered_destination: "", user_not_registered_vm_flag: "",
        no_answer_destination: "", no_answer_vm_flag: "", id, token
      })
    });
    const text = await res.text();
    if (text.includes("Invalid key found")) { session = null; continue; }   // token expired: log in again
    let result; try { result = JSON.parse(text); } catch { result = { text }; }
    if (res.ok && result.status === true && result.response_code === 200) return result;
    throw new Error("Forward failed: " + text);
  }
  throw new Error("Forward failed after logging in again");
}

app.post("/pbxme/incoming-call", (req, res) => {
  if (!WEBHOOK_IPS.has(req.ip)) return res.sendStatus(403);
  const call = req.body || {};
  if (!call.call_id || !call.did_id) return res.sendStatus(400);
  res.sendStatus(200);                          // confirm within 5 seconds

  const now = Date.now();
  for (const [k, v] of seen) if (now - v.at > SEEN_TTL_MS) seen.delete(k);
  const prev = seen.get(call.call_id);
  if (prev && prev.state !== "failed") return;  // a retry of a call already being routed or routed
  seen.set(call.call_id, { state: "pending", at: now });

  // Your logic picks the destination; here every caller goes to one phone number.
  forward(call.did_id, "4", "441234567890", now + ROUTE_DEADLINE_MS)   // 4 = PSTN
    .then(() => seen.set(call.call_id, { state: "routed", at: Date.now() }))
    .catch(err => { seen.set(call.call_id, { state: "failed", at: Date.now() }); console.error(err); });
});

// The destination you set becomes the number's forwarding and stays until you
// change it with another DID Forward Setting call; nothing switches it back
// automatically. So the NEXT call goes straight there, not to this webhook.
// To have the webhook decide again, set the number back to type "19" yourself
// (rearm below). Every call that arrives while the number is set to "19" is
// sent to this webhook.
async function rearm(didId, webhookUrl) {
  return forward(didId, "19", webhookUrl, Date.now() + 10000);
}

app.listen(3000);

Step 2: Point Your Number at the Webhook

Use the portal or the API.

2

In the portal

Go to Inbound → Local Numbers and click the blue Call Forward arrow next to your number. In Call Type, select Incoming Call Webhook, enter your webhook URL in the destination field, and click Save.

3

Or through the API

Call DID Forward Setting with call_type set to "19" and your webhook URL in call_type_value, keeping the other documented fields.

{
  "action": "forward",
  "did_id": "YOUR_DID_ID",
  "call_type": "19",
  "call_type_value": "https://example.com/pbxme/incoming-call"
}
Full request, authentication and field reference: PBXme API reference (Postman) · Incoming Call Webhook API

Step 3: Test an Incoming Call

4

Call your number

Log every request your webhook receives. Call the number from a phone: you should hear ringing, see the POST arrive and your server answer 200, then reach the destination once your server sets the forwarding.

Troubleshooting

No request reaches the server. Check that the number’s Call Type is Incoming Call Webhook (call_type 19), that the URL is complete and publicly reachable over HTTPS, and that your firewall allows POST requests from 195.201.136.88 and 95.217.164.101.

The call drops. Your server must answer 200 within 5 seconds (up to 5 attempts), and the forwarding must be set within 30 seconds of the call arriving. Respond first, then do slow lookups in the background.

The API rejects the forwarding call. If it returns “Invalid key found”, log in again and use the new id and token.

The webhook stopped receiving calls. Setting the destination saves it as the number’s forwarding. Set the number back to call_type 19 to receive the next calls on your webhook.

Want to stream the call to an AI voice app instead? Use VocRT WebSocket forwarding (call_type 17).

Contact us at support@pbxme.com or WhatsApp +972 55-966-4944.

Sales, click to chat