Requesting Help in API connection via PHP

Integration questions/issues
Post Reply
adamg
Posts: 4
Joined: Fri Mar 25, 2016 1:54 am

Requesting Help in API connection via PHP

Post by adamg » Mon Feb 04, 2019 10:47 pm

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 https://api.onlyoffice.com/portals/meth ... entication

My Non working code

Code: Select all

<?php
$url = 'http://MYORG.onlyoffice.com/api/2.0/authentication';

// 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

Carl
Posts: 160
Joined: Thu Apr 12, 2018 10:00 am

Re: Requesting Help in API connection via PHP

Post by Carl » Tue Feb 05, 2019 7:50 am

Hello,

The issue is in

Code: Select all

if ($server_output == "OK") { echo "WIN"; }
The authentication request returns a response like described here: https://api.onlyoffice.com/portals/auth

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

adamg
Posts: 4
Joined: Fri Mar 25, 2016 1:54 am

Re: Requesting Help in API connection via PHP

Post by adamg » Wed Feb 06, 2019 1:12 am

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 https://api.onlyoffice.com/portals/auth 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.

Post Reply