SIP headers (also called SIP fields) are part of every HTTP request made by an outbound call. They can convey message attributes to ensure that information packets travel along the correct path between devices on different networks.
SIP headers are categorized into four main types: record-route headers, route headers, via headers, and contact headers. They always have the format
<header_name>:<value>
Plivo SIP headers are always prefixed with X-PH-
. Only characters [A-Z], [a-z], and [0-9] are allowed as part of either a SIP header name or value to ensure that you can encode them in a URL. You can use multiple header fields by entering them as a comma-separated list:
head1=val1,head2=val2,head3=val3,...,headn=valn
You can use custom SIP headers to pass information (such as customer ID or product information) from a front-end application to a back-end application and vice versa.
If you’re using a SIP endpoint and you’ve configured it to send custom SIP headers, Plivo will send the SIP headers with your HTTP request.
You can pass custom SIP headers either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.
You can create and deploy a PHLO to make an outbound call with custom SIP headers with a few clicks on the PHLO canvas.
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first PHLO, follow our instructions to set up a PHP development environment.
To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.
Your PHLO is now ready to test.
You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.
In either case, you need your Auth ID and Auth Token, which you can get from the overview page of the Plivo console.
When you configure values when creating the PHLO, they act as a static payload.
Create a file called TriggerPhlo.php
and paste into it this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new PhloRestClient("<auth_id>", "<auth_token>");
$phlo = $client->phlo->get("<phlo_id>");
try {
$response = $phlo->run();
print_r($response);
} catch (PlivoRestException $ex) {
print_r($ex);
}
Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console.
To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO and pass the values from your code when you trigger it.
Create a file called TriggerPhlo.php
and paste into it this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new PhloRestClient("<auth_id>", "<auth_token>");
$phlo = $client->phlo->get("<phlo_id>");
try {
$response = $phlo->run(["from" => "<caller_id>", "to" => "<destination_number>"]); // These are the fields entered in the PHLO console
print_r($response);
} catch (PlivoRestException $ex) {
print_r($ex);
}
Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).
Save the file and run it.
$ php TriggerPhlo.php
Here’s how to use Plivo APIs and XML to make an outbound call with custom SIP headers.
Plivo requests an answer URL when the call is answered (step 4) and expects the file at that address to hold a valid XML response from the application with instructions on how to handle the call. To see how this works, you can use https://s3.amazonaws.com/static.plivo.com/answer.xml as an answer URL to test your first outgoing call. The file contains this XML code:
<Response>
<Speak>Congratulations! You've made your first outbound call!</Speak>
</Response>
This code instructs Plivo to say, “Congratulations! You’ve made your first outbound call!” to the call recipient. You can find the entire list of valid Plivo XML verbs in our XML Reference documentation.
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a PHP development environment.
Create a file called MakeCall.php
and paste into it this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new RestClient("<auth_id>","<auth_token>");
try {
$response = $client->calls->create(
'<caller_id>',
['<destination_number>'],
'https://s3.amazonaws.com/static.plivo.com/answer.xml',
[
'ring_url' => 'https://WWW.RING.URL',
'sip_headers' => 'Test=Sample',
'answer_method' => 'GET'
]
);
print_r($response);
}
catch (PlivoRestException $ex) {
print_r($ex);
}
Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234). Destination_number may also be a SIP endpoint, in which case the destination_number placeholder must be a valid SIP URI — for example, sip:john1234@phone.plivo.com.
Save the file and run it.
$ php MakeCall.php
(201, {
u'message': u'call fired',
u'request_uuid': u'85b1d45d-bc12-47f5-89c7-ae4a2c5d5713',
u'api_id': u'ad0e27a8-9008-11e4-b932-22000ac50fac'
}
)
The SIP header can be seen as a query parameter in the answer_url
/answer.xml?Direction=outbound&From=1111111111&ALegUUID=5260e820-958c-11e4-b6bf-498d468c930b&BillRate=0.00300&
To=sip%3Aabcd150105094929%40phone.plivo.com&<mark>X-PH-Test=Sample</mark>&CallUUID=5260e820-958c-11e4-b6bf-498d468c930b&ALegRequestUUID=2202d0ab-a890-4199-8582-e7a2615cb23b&
RequestUUID=2202d0ab-a890-4199-8582-e7a2615cb23b&SIP-H-To=%3Csip%3Aabcd150105094929%40phone.plivo.com%3E%3Btag%3D6U9J4.uVHI7KyEKSgD8vrPnAKQoR2QXc&
CallStatus=in-progress&Event=StartApp