Jump to content

Help with Code PHP and XML


barne77

Recommended Posts

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);

 

?>

Link to comment
Share on other sites

"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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.