Try the fastest and simplest way to install ONLYOFFICE

Getting Started API PHP

Integration questions/issues

Getting Started API PHP

Postby adamg » Fri Mar 25, 2016 2:16 am

Hi All,

I have been playing with PHP for many years. however never used an API. http://api.onlyoffice.com/portals/auth unfortunately doesn't make any sense to me.

Is someone kind enough to pass me to specific pages and references on how i can achieve a connection and return perhaps a list of projects?

I'm certainly happy to do the work in learning here, however i'm stuck on how to start.

Is there a full example of:
    Code required to make a authentication
    Code required to fetch data from the portal
    Code required to post data to the portal

I assume once i have a working example of this the rest of the api will fall into place on how i can utilize it.

Thank you in advance.
adamg
 
Posts: 3
Joined: Fri Mar 25, 2016 1:54 am

Re: Getting Started API PHP

Postby Dean » Mon Apr 25, 2016 1:38 pm

1) To pass authentification, you have to send a POST request with the following body:

POST /api/2.0/authentication.json HTTP/1.1
Host: portal.onlyoffice.com
Accept: application/json,application/xml
Accept-Encoding: gzip, deflate
userName=yourusername&password=yourpassword

2, 3) There are different examples for each module:

http://api.onlyoffice.com/portals/metho ... act/filter - for getting contact data.

All the requests examples you may find on http://api.onlyoffice.com/portals
Dean
 
Posts: 700
Joined: Tue Sep 30, 2014 11:04 am

Re: Getting Started API PHP

Postby adamg » Mon Sep 19, 2016 3:58 am

For those who want a real answer.

To create your authorization key
Code: Select all
<?php
$url = 'http://YOUR PORTAL ADDRESS/api/2.0/authentication.json';
$fields = array(
   'username' => urlencode('YOUR  USERNAME'),
   'password' => urlencode('YOUR PASSWORD'),
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);


-------------------------------------------------------------------------------

Code: Select all
<?php
$url = 'http://YOUR PORTAL ADDRESS/API/2.0/PROJECT/TASK/FILTER?status=1';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: SPECIFIC AUTHORISATION CODE FROM PREVIOUS STEP', 'Accept: application/json,application/xml', 'Accept-Encoding: gzip, deflate'));
$result = curl_exec($ch);
//decode the results so you can use them
$r2 = json_decode($result, true);
curl_close($ch);
//dump the results so you can view the format and start assigning code
print_r($r2);
adamg
 
Posts: 3
Joined: Fri Mar 25, 2016 1:54 am


Return to API

Who is online

Users browsing this forum: No registered users and 2 guests