knowram Posted July 17, 2013 Share Posted July 17, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/ Share on other sites More sharing options...
Muddy_Funster Posted July 17, 2013 Share Posted July 17, 2013 I don't actualy get what you are trying to do here... Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/#findComment-1441069 Share on other sites More sharing options...
knowram Posted July 17, 2013 Author Share Posted July 17, 2013 If I understand the API correctly I am trying to do 'POST','GET','PUT' or 'DELETE' functions with an XML payload. but even saying that I am not sure what it means. Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/#findComment-1441073 Share on other sites More sharing options...
boompa Posted July 17, 2013 Share Posted July 17, 2013 You should really take the time to learn how to use the cURL library to make your http requests. In any event, just telling us it doesn't work without more detail into how it is not meeting your needs is sort of useless. Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/#findComment-1441081 Share on other sites More sharing options...
AbraCadaver Posted July 17, 2013 Share Posted July 17, 2013 Why not use the HTTP classes from PHP? http://us3.php.net/manual/en/class.httprequest.php Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/#findComment-1441083 Share on other sites More sharing options...
knowram Posted July 17, 2013 Author Share Posted July 17, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/280240-using-xml-api-with-php/#findComment-1441097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.