Mohammad Mohammad - 7 months ago 29
PHP Question

SAASU API not returnig response using rest api

I sending request to SAASU to create new contact using REST API but i am not getting result.
Please help me.

Method-1

$web_service = 'https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';

$xml = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';

$cmd = 'curl -X '.' "'.$xml.'" '.$web_service;

exec($cmd, $result);

print_r($result); // Getting Null


Method-2

$curlData = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';
$url = https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'SOAPAction:""',
'Content-Type: text/xml; charset=utf-8',
));

curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

$result = curl_exec($curl);
curl_close ($curl);
print_r($result); //NULL RESULT


Saasu help : http://help.saasu.com/api/

Answer

Finally, got the response. Here is the code

$curlData = '<?xml version="1.0" encoding="utf-8"?><tasks><insertContact><contact uid="0"><salutation>Mr.</salutation><familyName>Smith</familyName><givenName>John</givenName><organisationName></organisationName></contact></insertContact></tasks>';
$url = https://secure.saasu.com/webservices/rest/r1/Tasks?wsaccesskey=XXXXXXXXXXXXXXXXX&FileUid=XXX';

$curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $url);
    //curl_setopt ($curl, CURLOPT_URL, "http://www.php.net");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt ($curl, CURLOPT_POST, 1);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

   $curl_response = curl_exec ($curl);
    curl_close ($curl);

    $xml = new SimpleXMLElement($curl_response);
    print_r($xml);

Thanks

Comments