sipsorcery's blog

Occassional posts about VoIP, SIP, WebRTC and Bitcoin.

sipsorcery.com response times SIP Sorcery Last 3 Hours
daily weekly
sipsorcery.com status

Accessing Provisioning Service with jquery

It’s been a while, at least 5 years, but I’ve eventually ended up back in the bottomless pit of frustration that is javascript. Actually it’s not that bad these days thanks to jquery although it’s still far from what I’d call pleasurable. It wasn’t an entirely voluntary decision for me, my day job requires me to get down and dirty with a web application and that means javascript and jquery.

Anyway I have whipped up a quick little sample to query the SIP Sorcery provisioning service to retireve a list of SIP accounts using jquery. It might be useful to someone and as with the previous samples if there is any interest I’m happy to flesh out the remainder of the REST interface to make it usable.

<html>
<head>
<title>SIP Sorcery jquery sample</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var PROVISIONING_URL = "https://www.sipsorcery.com/provisioning.svc/rest/";

$(document).ready(function() {
login("yourusername", "yourpassword");
});

function login(user, pass) {
$.get(
PROVISIONING_URL + "customer/login",
{ username: user, password: pass },
function(data){
getSIPAccounts(data);
});
}

function getSIPAccounts(authid) {
$.ajax({
beforeSend: function(req) {
req.setRequestHeader("AuthID", authid);
},
url: PROVISIONING_URL + "sipaccounts?count=3",
dataType: 'json',
success: function(data){
$.each(data, function(index, sipAccount) {
alert("Username: " + sipAccount.SIPUsername);
})
},
error: function(xhr) {
alert ("Oopsie: " + xhr.statusText);
}
});
}

</script>
</head>
<body>
SIP Sorcery jquery test
</body>
</html>