using cURL in Asterisk Dialplan

There are many times when you need to interact with external application within Asterisk dialplan. Using the cURL function of asterisk dialplan we can POST/GET whatever information we have to any URL.

Configuration

Make sure curl is on your system (on “Ubuntu 8.04 server” users can run apt-get install libcurl4-dev) Then in the asterisk sources re-run the ./configure script and check if it detects curl. Run make menuselect and look under the Dialplan Functions for the func_curl entry, making sure there are no XXX’s there before compiling and installing asterisk.

Example

exten => s,1,Set(foo=${CURL(http://somewhere.com/somepage.html?x=5&y=4)})

Example (POST-Method):

 exten => _X.,2,curl(http://www.somehost.com/may_be_a_dir/file_to_call.php,
                                                postdata_var1=1&postdata_var2=something)
 exten => _X.,3,Wait(5)
 exten => _X.,4,NoOp(CURL-RESPONSE: ${CURL})

Example (GET-Method):

 exten => _X.,2,curl(http://www.somehost.com/may_be_a_dir/file_to_call.php?
                     postdata_var1=1&postdata_var2=something)
 exten => _X.,3,Wait(5)
 exten => _X.,4,NoOp(CURL-RESPONSE: ${CURL})

Reference:

>Asterisk – documentation of application commands

>Asterisk cmd Curl

>Asterisk func curl

You may also like