Jump to content

using XML API with PHP


knowram

Recommended Posts

Hello all. I am a self taught developer and therefore only know what i have done so please be nice. I am trying to figure out how to use an XML API from cisco. They have given the following example.

POST http://<server>/vmrest/users?templateAlias=voicemailusertemplate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<User>
<Alias>jdoe</Alias>
<DtmfAccessId>7890</DtmfAccessId>
</User>

presumably if I really knew what I was doing this would make sense to me however it does not. I would like to be able to perform this function through a web interface with php. After doing some searching I found the following bit of code that I tried manipulate to  to complete the function above however I am having problems getting it to work. 

<?php
  //You can use 'POST','GET','PUT' or 'DELETE'
  $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <User>
  <Alias>jdoe</Alias>
  <DtmfAccessId>7890</DtmfAccessId>
  </User>';
$auth = base64_encode('username:password');
$header = array("Authorization: Basic $auth");


$opts = array(
    'http'=>array(
        'method'=>'POST',
        'header'=>$header,
        'content'=>$xml
    )
);


$context = stream_context_create($opts);


/* Sends an http request to www.example.com
with additional headers shown above */
$url = 'http://172.16.16.121/vmrest/users?templateAlias=voicemailusertemplate';
$fp = fopen($url, 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

If anyone could help point me in the right direction I would much appreciate it. Thank you

Link to comment
Share on other sites

thank you guys for the input. I understand that just saying it doesn't work is not really helpful. I did that mostly because I am still trying to figure out the best way to do this. I have seen some posts that talk about the cURL library and now AbraCadaver has suggested HTTP classes. I am looking for something simple that I can simply update the XML that needs to be sent as well as the action ( POST, PUT, DELETE, GET). Sorry I didn't write the original post this way it's mostly only now become clear that this was my intention for this post. I know this is allot but would you be able to share an example of a POST with each method (cURL, HTTP classes) that has authentication by any chance? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.