Skip to content

Instantly share code, notes, and snippets.

@catlike
Created November 6, 2010 01:28
Show Gist options
  • Save catlike/665107 to your computer and use it in GitHub Desktop.
Save catlike/665107 to your computer and use it in GitHub Desktop.
PHP example of creating a SIP account on Cloudvox
<?php
//Name of Cloudvox Account
$CVAccountName = 'foo';
//URL to post to create SIP account
$url ="https://$CVAccountName.cloudvox.com/phones.json";
//Extension to create
$extension = '2720';
//Username to tie to extension
$username = 'johnny';
//Password to tie to extension
$password = 'qwerty1';
//JSON to pass to API
$postdata = array('endpoint'=>array('extension'=>$extension,'username'=>$username,'password'=>$password));
// YOU HAVE TO URL ENCODE MULTI-DIMENSIONAL ARRAYS IN PHP BEFORE PASSING TO cURL
$postdata = http_build_query($postdata);
echo $postdata;
echo "\n\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_USERPWD, "[email protected]:STRONGpassword");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_getinfo($ch);
echo $info['url'];
echo "\n\n";
$result =curl_exec($ch);
curl_close($ch);
echo $result;
echo "\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment