How XML Works
Incoming Calls
- Someone calls your Plivo phone number
- Plivo sends a request to your Answer URL
- Your server returns Plivo XML instructions
- Plivo executes the instructions (speak, play, dial, etc.)
Outbound Calls
- You trigger an outbound call via the API with an
answer_url - When the call is answered, Plivo fetches XML from your
answer_url - Plivo executes the instructions
Basic Structure
Every Plivo XML document starts with a<Response> element containing one or more instruction elements:
Multiple Elements
- Speak the message
- Play the audio file
- Dial the number
- If dial fails, speak the fallback message
- Hang up
Generating XML with SDKs
Available XML Elements
Audio Output
Input Collection
Call Routing
Conferencing
| Element | Description |
|---|---|
| Conference | Connect caller to a conference room |
| MultiPartyCall | Advanced multi-party conferencing |
Recording
| Element | Description |
|---|---|
| Record | Record the call or a message |
Advanced
Nesting Elements
Some elements can be nested inside others:Nesting Rules
| Parent Element | Allowed Children |
|---|---|
| Response | All elements |
| GetDigits | Speak, Play |
| GetInput | Speak, Play |
| Dial | Number, User |
| PreAnswer | Speak, Play, Wait |
Request Parameters
When Plivo requests your XML endpoint, it includes these parameters:Voice Call Parameters
| Parameter | Description |
|---|---|
CallUUID | Unique identifier for this call |
From | Caller’s phone number (with country code) |
To | Called phone number (with country code) |
CallStatus | Call status: ringing, in-progress, completed |
Direction | inbound or outbound |
Inbound vs Outbound
Inbound calls:From= Caller’s numberTo= Your Plivo numberDirection=inbound
From= Caller ID you specifiedTo= Destination numberDirection=outbound
Outbound Call Parameters
| Parameter | Description |
|---|---|
ALegUUID | UUID of the first call leg |
ALegRequestUUID | Request UUID returned by API |
Call Forwarding
| Parameter | Description |
|---|---|
ForwardedFrom | Original number (if call was forwarded). Carrier-dependent |
Completed Call Parameters
| Parameter | Description |
|---|---|
HangupCause | Standard telephony hangup cause |
Duration | Call duration in seconds |
BillDuration | Billed duration in seconds |
TotalCost | Total cost of the call |
Call Status Values
| Status | Description |
|---|---|
ringing | Call is ringing (inbound, not yet answered) |
in-progress | Call is active |
completed | Call ended normally |
busy | Called party was busy (outbound only) |
failed | Call failed to connect (outbound only) |
timeout | No answer within timeout (outbound only) |
no-answer | Called party didn’t answer (outbound only) |
SIP Headers
For SIP calls, custom SIP headers are included with theX-PH- prefix:
| Header Format | Description |
|---|---|
X-PH-<HeaderName> | Custom SIP header value |
sipHeaders="CustomId=123", the request includes X-PH-CustomId=123.
Response Requirements
Your server must return:- Valid XML document
- Content-Type:
application/xmlortext/xml - Maximum size: 100 KB
Framework Examples
Empty Response
An empty<Response> element hangs up the call:
Example: Using Request Parameters
Example: Simple IVR
Example: Forward Call
Hangup Causes
Common hangup cause values:| Cause | Description |
|---|---|
NORMAL_CLEARING | Normal call termination |
USER_BUSY | Called party busy |
NO_ANSWER | No answer within timeout |
CALL_REJECTED | Call was rejected |
UNALLOCATED_NUMBER | Invalid number |
NETWORK_OUT_OF_ORDER | Network issues |
Best Practices
- Always return valid XML - Malformed XML will cause call failures
- Use HTTPS - All callback URLs should use HTTPS
- Handle timeouts - Include fallback behavior for user input
- Test thoroughly - Use ngrok for local development testing
- Log callback data - Store request parameters for debugging
- Return quickly - Plivo has a 15-second timeout for XML responses
Error Handling
If your server returns invalid XML:- The call may hang up unexpectedly
- Plivo logs the error in your console
- Malformed XML (unclosed tags)
- Wrong content type
- Empty response
- Response too large
Related
- Audio Output - Speak, Play, DTMF
- Input Collection - GetDigits, GetInput
- Call Routing - Dial, Redirect, Hangup, Wait
- Conferencing - Conference, MultiPartyCall
- Recording - Record calls and messages
- Audio Streaming - Stream real-time audio