Page 1 of 1

Requesting Help in API connection via PHP

Posted: Mon Feb 04, 2019 10:47 pm
by adamg
Hi All,

I am wondering if there is anyone out there that can assist me with some template code on how to generate and authenticate to the CRM portal (Nothing document related)

I have been unsuccessful in my attempts to generate a code and create the authentication request as per ... entication

My Non working code

Code: Select all

$url = '';

// A very simple PHP example that sends a HTTP POST to a remote site
$data = array("userName" => "MY_EMAIL", "password" => "MY PASSWORD");                                                                    
$data_string = json_encode($data);   

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);
curl_close ($ch);

print_r($server_output);  //Try and get some form of output
// Further processing ...
if ($server_output == "OK") { echo "WIN"; } else { echo "FAIL"; }
I'm obviously missing fundermental understanding and would really appreciate anyones help

Re: Requesting Help in API connection via PHP

Posted: Tue Feb 05, 2019 7:50 am
by Carl

The issue is in

Code: Select all

if ($server_output == "OK") { echo "WIN"; }
The authentication request returns a response like described here:

This response is not "OK", so you get a "FAIL" result.

Re: Requesting Help in API connection via PHP

Posted: Wed Feb 06, 2019 1:12 am
by adamg
Hi Carl,

Thanks for your prompt input. Very much appreciated.

I currently cant get anything from $server_output.
Can you see anything above that would indicate it not work?

As im not great at getting these authentications started the page doesnt give me what im missing.
I assumed i was already performing a CURLrequest as per the example.

I have tried a few variations of this with the headers too.
In short, my insufficient knowledge at this stage has prevented me moving forward.

Any advice would be appreciated.