Skip to main content
Plivo XML is a set of instructions you use to tell Plivo what to do when you receive an incoming call or make an outbound call. When someone calls your Plivo phone number, Plivo looks up the URL associated with that phone number and makes a request to that URL. Your web application returns an XML document with instructions on how to handle the call.

How XML Works

Incoming Calls

  1. Someone calls your Plivo phone number
  2. Plivo sends a request to your Answer URL
  3. Your server returns Plivo XML instructions
  4. Plivo executes the instructions (speak, play, dial, etc.)
Incoming call
  1. Caller
  2. Plivo
  3. Your ServerAnswer URL
  4. XML Response
  5. PlivoExecutes

Outbound Calls

  1. You trigger an outbound call via the API with an answer_url
  2. When the call is answered, Plivo fetches XML from your answer_url
  3. Plivo executes the instructions
Outbound call
  1. Your App
  2. Plivo API
  3. Call Recipient
  4. XMLfrom answer_url
  5. Execute

Basic Structure

Every Plivo XML document starts with a <Response> element containing one or more instruction elements:
Elements are executed in order. When one element completes, the next begins.

Multiple Elements

Execution flow:
  1. Speak the message
  2. Play the audio file
  3. Dial the number
  4. If dial fails, speak the fallback message
  5. Hang up

Generating XML with SDKs


Available XML Elements

Audio Output

Input Collection

Call Routing

Conferencing

Recording

Advanced


Nesting Elements

Some elements can be nested inside others:

Nesting Rules


Request Parameters

When Plivo requests your XML endpoint, it includes these parameters:

Voice Call Parameters

Inbound vs Outbound

Inbound calls:
  • From = Caller’s number
  • To = Your Plivo number
  • Direction = inbound
Outbound calls (via API):
  • From = Caller ID you specified
  • To = Destination number
  • Direction = outbound

Outbound Call Parameters

Call Forwarding

Completed Call Parameters

Call Status Values

SIP Headers

For SIP calls, custom SIP headers are included with the X-PH- prefix: Example: If you send sipHeaders="CustomId=123", the request includes X-PH-CustomId=123.

Response Requirements

Your server must return:
  • Valid XML document
  • Content-Type: application/xml or text/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:

Best Practices

  1. Always return valid XML - Malformed XML will cause call failures
  2. Use HTTPS - All callback URLs should use HTTPS
  3. Handle timeouts - Include fallback behavior for user input
  4. Test thoroughly - Use ngrok for local development testing
  5. Log callback data - Store request parameters for debugging
  6. 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
Common issues:
  • Malformed XML (unclosed tags)
  • Wrong content type
  • Empty response
  • Response too large