barne77 Posted May 4, 2017 Share Posted May 4, 2017 Hi I have the code below but it doesn't work This is a .PHP page and I am trying to log a request in ManageEngine Please Help Urgent I just get Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\TAF System\Live\ME.php:40 Stack trace: #0 D:\TAF System\Live\ME.php(40): SimpleXMLElement->__construct('') #1 {main} thrown in D:\TAF System\Live\ME.php on line 40 <?php$operation_name = 'ADD_REQUEST';$technician_key = '9E42EE6D-94A5-4B2E-B96D-DF01BBC1A6EB';$requester_name = 'Phil Barnett';$subject = 'TEST JOB';$description = 'Description';$callbackURL = 'http://localhost:8080/CustomReportHandler.do';$requesttemplate = 'Unable to Browse';$priority = 'High';$site = 'New York';$group = 'Network';$technician = 'Phil Barnett';$level = 'Tier 1';$status = 'Open';$service = 'Email';//Url to Send the Http request to Add the New Record into the Manage Engine Service Desk Plus //Xml String (Record Field Values) $data = '<xml><Operation><Details><requester>'.$requester_name.'</requester><subject>'.$subject.'</subject><description>'.$description.'</description><callbackURL>'.$callbackURL.'</callbackURL><requesttemplate>'.$requesttemplate.'</requesttemplate><priority>'.$priority.'</priority><site>'.$site.'</site><group>'.$group.'</group><technician>'.$technician.'</technician><level>'.$level.'</level><status>'.$status.'</status><service>'.$service.'</service></Details></Operation></xml>'; $url = 'http://localhost:8080/sdpapi/request/?OPERATION_NAME='.$operation_name.'&TECHNICIAN_KEY='.$technician_key.'&INPUT_DATA='; //this line is used to update the existing record of Manage Engine //$data1='<xml><Operation><Details><level>Tier 2</level><status>On Hold</status><service>Email</service></Details></Operation></xml>'; $path = implode('/', array_map('rawurlencode', explode('/', $data)));$url2 = $url.$path; $ch = curl_init();curl_setopt( $ch, CURLOPT_URL, $url2);curl_setopt( $ch, CURLOPT_POST, true );curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );$result = curl_exec($ch); print_r($url2); $xml = new SimpleXMLElement($result); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted May 4, 2017 Share Posted May 4, 2017 Are you sure you're calling the API correctly? XML data in the URL during a POST request is highly unusual. Regardless, output $result and see what the service actually returned. Quote Link to comment Share on other sites More sharing options...
barne77 Posted May 4, 2017 Author Share Posted May 4, 2017 print_r($result); give me nothing as an output. It is for a system called Manage Engine Service Desk, I used a http-request previously and that worked fine Barne77 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 4, 2017 Share Posted May 4, 2017 "Nothing" doesn't exist in programming. Is the return value false? An empty string? Something else? Use var_dump($result) instead of this print_r() stuff. In any case, your request is very, very weird. You're taking the slashes of the closing XML tags as path delimiters. On what planet does this make sense? Quote Link to comment Share on other sites More sharing options...
barne77 Posted May 4, 2017 Author Share Posted May 4, 2017 bool(false) Quote Link to comment Share on other sites More sharing options...
barne77 Posted May 4, 2017 Author Share Posted May 4, 2017 i pulled the script from another site, basically i need to do a REST POST for the API This includes the http which is $url = 'http://localhost:8080/sdpapi/request/?OPERATION_NAME='.$operation_name.'&TECHNICIAN_KEY='.$technician_key.'&INPUT_DATA='; and then the xml code for the input data Barne77 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 4, 2017 Share Posted May 4, 2017 bool(false) Then the request has failed entirely. curl_error() tells you the actual error message. Quote Link to comment Share on other sites More sharing options...
barne77 Posted May 4, 2017 Author Share Posted May 4, 2017 DOH What is the best way to do a REST POST using PHP, i am really struggling, Quote Link to comment Share on other sites More sharing options...
barne77 Posted May 4, 2017 Author Share Posted May 4, 2017 i am really new to this and only have the following url to help https://www.manageengine.com/products/service-desk/help/adminguide/api/request-operations.html#add Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 4, 2017 Share Posted May 4, 2017 I've just told you how to get the exact error message. Now you have to do that. The API manual you've linked to clearly says that the XML data is expected as a parameter in the request body (they call it "POST attribute"). Not in the URL. There are plenty of examples explaining exactly how to build a POST request, so I'm sure you can figure it out. 1 Quote Link to comment 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.