Add Custom SIP Headers

SIP headers (also called SIP fields) is a function of SIP. These headers help convey message attributes to ensure that information packets travel along the correct path when communicating between devices existing on separate networks. SIP headers are present for every HTTP request made by an outbound call and can be categorized into four main types: record route headers, route headers, via headers, and contact headers. Simply put, SIP headers are similar to HTTP header fields and always have the following format:

<header_name>:<value>

SIP headers are always prefixed with X-PH-. Only [A-Z], [a-z] and [0-9] characters are allowed for the SIP header key. Only [A-Z], [a-z], [0-9] and ‘%’ characters are allowed for the SIP header value to ensure that you can encode this value in a URL. You may add multiple header fields by entering the value as a comma-separated list. For example:

head1=val1,head2=val2,head3=val3,...,headN=valN

If you are using a SIP endpoint and have configured your SIP phone to send custom SIP headers, then Plivo will send these SIP headers with your HTTP Request.

The following API enables you to make a single call or bulk outbound calls to real phone(s) or SIP endpoint(s). The following tutorial will show you how to add custome SIP headers.

POSThttps://api.plivo.com/v1/Account/{auth_id}/Call/

Prerequisites

Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.

Implementation

Note: Be sure to save it with the appropriate file extension for your language (i.e., .py for Python or .rb for Ruby, etc.).

Replace 'Your AUTH_ID' and 'Your AUTH_TOKEN' with the AUTH ID and AUTH TOKEN found on your Plivo dashboard.

Add your 'from' (source) phone number. This will show up as your Sender ID. Be sure that all phone numbers include country code, area code, and phone number without spaces or dashes (e.g., 14153336666).

Note: If you are using a trial account, your destination number needs to be verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.

Edit the 'answer_url' field with your hosted url which is invoked by Plivo when the call is answered.

Edit the 'answer_method' field with either GET or POST.

Add your Sip Headers to 'sip_headers' field. List of SIP headers are in the form of ‘key=value’ pairs, separated by commas. E.g. head1=val1,head2=val2,head3=val3,…,headN=valN. The SIP headers are always prefixed with X-PH-. The SIP headers are present for every HTTP request made by the outbound call. Only [A-Z], [a-z] and [0-9] characters are allowed for the SIP headers key and value. Additionally, the ‘%’ character is also allowed for the SIP headers value so that you can encode this value in the URL.

Code

importplivoauth_id="Your AUTH_ID"auth_token="Your AUTH_TOKEN"p=plivo.RestAPI(auth_id,auth_token)params={'to':'sip:abcd150105094929@phone.plivo.com',# The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:
'from':'1111111111',# The phone number to be used as the caller id
'answer_url':"https://s3.amazonaws.com/static.plivo.com/answer.xml",# The URL invoked by Plivo when the outbound call is answered
'answer_method':"GET",# Method to invoke the answer_url
'sip_headers':"Test=Sample"# List of SIP headers in the form of 'key=value' pairs, separated by commas.
}# Make an outbound call
response=p.make_call(params)printstr(response)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

require'rubygems'require'plivo'includePlivoAUTH_ID="Your AUTH_ID"AUTH_TOKEN="Your AUTH_TOKEN"p=RestAPI.new(AUTH_ID,AUTH_TOKEN)params={'to'=>'sip:abcd150105094929@phone.plivo.com',# The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:'from'=>'1111111111',# The phone number to be used as the caller id'answer_url'=>'https://s3.amazonaws.com/static.plivo.com/answer.xml',# The URL invoked by Plivo when the outbound call is answered'answer_method'=>'GET',# The method used to call the answer_url'sip_headers'=>"Test=Sample"# List of SIP headers in the form of 'key=value' pairs, separated by commas.}# Make an outbound callresponse=p.make_call(params)printresponse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

varplivo=require('plivo');varp=plivo.RestAPI({"authId":"auth id comes here","authToken":"auth token comes here",});varparams={};params.from="1111111111";// The phone number to be used as the caller idparams.to="sip:abcd150105094929@phone.plivo.com";// The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:params.answer_url="https://s3.amazonaws.com/static.plivo.com/answer.xml";// The URL invoked by Plivo when the outbound call is answeredparams.answer_method="GET";// Method to invoke the answer_urlparams.sip_headers="Test=Sample"// List of SIP headers in the form of 'key=value' pairs, separated by commas.p.make_call(params,function(status,response){console.log('Status: ',status);console.log('API Response:\n',response);});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

<?phprequire'vendor/autoload.php';usePlivo\RestAPI;$auth_id="Your AUTH_ID";$auth_token="Your AUTH_TOKEN";$p=newRestAPI($auth_id,$auth_token);$params=array('to'=>'sip:abcd150105094929@phone.plivo.com',# The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:'from'=>'2222222222',# The phone number to be used as the caller id'answer_url'=>"https://s3.amazonaws.com/static.plivo.com/answer.xml",# The URL invoked by Plivo when the outbound call is answered'answer_method'=>"GET",# The method used to call the answer_url'sip_headers'=>"Test=Sample",# List of SIP headers in the form of 'key=value' pairs, separated by commas.);# Make an outbound call$response=$p->make_call($params);print_r($response);?>

packagecom.plivo.test;importjava.util.LinkedHashMap;importcom.plivo.helper.api.client.*;importcom.plivo.helper.api.response.call.Call;importcom.plivo.helper.exception.PlivoException;publicclassApp{publicstaticvoidmain(String[]args)throwsIllegalAccessException{Stringauth_id="Your AUTH_ID";Stringauth_token="Your AUTH_TOKEN";RestAPIapi=newRestAPI(auth_id,auth_token,"v1");LinkedHashMap<String,String>parameters=newLinkedHashMap<String,String>();parameters.put("to","sip:abcd150108095716@phone.plivo.com");// The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:parameters.put("from","1111111111");// The phone number to be used as the caller idparameters.put("answer_url","https://s3.amazonaws.com/static.plivo.com/answer.xml");// The URL invoked by Plivo when the outbound call is answeredparameters.put("answer_method","GET");// Method to invoke the answer_urlparameters.put("sip_headers","Test=Sample");// List of SIP headers in the form of 'key=value' pairs, separated by commas.try{Callresp=api.makeCall(parameters);System.out.println(resp);}catch(PlivoExceptione){System.out.println(e.getLocalizedMessage());}}}

usingSystem;usingSystem.Collections.Generic;usingRestSharp;usingPlivo.API;namespacecustom_sip_header{classProgram{staticvoidMain(string[]args){RestAPIplivo=newRestAPI("Your AUTH_ID","Your AUTH_TOKEN");IRestResponse&lt;Call&gt;resp=plivo.make_call(newDictionary&lt;string,string&gt;(){{"from","1111111111"},// The phone number to which the call has to be placed{"to","sip:abcd150105094929@phone.plivo.com"},// The phone numer to which the all has to be placed. Sip endpoints must be prefixed with sip:{"answer_url","https://s3.amazonaws.com/static.plivo.com/answer.xml"},// The URL invoked by Plivo when the outbound call is answered{"answer_method","GET"},// The method used to invoke the answer_url{"sip_headers","Test=Sample"}// List of SIP Headers in the form of 'key=value' pairs, separated by commas});//Prints the responseConsole.Write(resp.Content);Console.ReadLine();}}}