Passing authentication
The user needs to perform several easy steps to pass authentication:
-
Send POST request, containing the userName and password parameters to the api/2.0/authentication address:
- Request
- Response
POST /api/2.0/authentication.json HTTP/1.1Host: yourportal.onlyoffice.comContent-Type: application/jsonAccept: application/json{"userName": "yourusername","password": "yourpassword"}noteYou have to enter your own portal address to the Host: yourportal.onlyoffice.com line instead of yourportal.onlyoffice.com address.
HTTP/1.1 201 CreatedCache-Control: privateContent-Type: application/json; charset=utf-8{"count": 1,"response": {"expires": "2010-07-07T17:06:03.5845502+03:00","token": "sdjhfskjdhkqy739459234"},"status": 0,"statusCode": 201} -
In case authentication is successful, a token which will look like sdjhfskjdhkqy739459234 will be received.
-
Use this token every time you call API methods inserting it to the Authorization HTTP header:
Sample API Request:
GET /api/2.0/people/@self.json HTTP/1.1Host: yourportal.onlyoffice.comAccept: application/jsonAuthorization: sdjhfskjdhkqy739459234noteYou have to enter your own portal address to the Host: yourportal.onlyoffice.com line instead of yourportal.onlyoffice.com address.
Authentication request examples
- C#
- cURL
var request = System.Net.WebRequest.Create("https://yourportal.onlyoffice.com/api/2.0/authentication.json");
request.Method = "POST";
request.ContentType = "application/json";
var body = "{\"userName\":\"yourusername\",\"password\":\"yourpassword\"}";
var data = System.Text.Encoding.UTF8.GetBytes(body);
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (System.Net.HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
You have to enter your own portal address instead of yourportal.onlyoffice.com address.
curl --request POST --header "Content-Type: application/json" --data "{\"username\":\"yourusername\",\"password\":\"yourpassword\"}" "https://yourportal.onlyoffice.com/api/2.0/authentication.json"
You have to enter your own portal address instead of yourportal.onlyoffice.com address.