跳到主要内容

Personal access tokens

Follow these steps to generate a PAT and use it to authorize your DocSpace account:

  1. Send a POST request containing the userName and password parameters to the api/2.0/authentication address:

    POST /api/2.0/authentication HTTP/1.1
    Host: yourportal.onlyoffice.com
    Content-Type: application/json
    Accept: application/json

    {
    "userName": "yourusername",
    "password": "yourpassword"
    }
    备注

    You have to enter your own portal address to the Host: yourportal.onlyoffice.com line instead of yourportal.onlyoffice.com address. For security purposes, store your username and password in env variables and reference them in the request.

  2. If authentication is successful, you will receive an API response containing a token with its lifetime.

  3. Use this token every time you call API methods inserting it to the Authorization HTTP header:

    Example API Request:

    GET /api/2.0/people/@self HTTP/1.1
    Host: yourportal.onlyoffice.com
    Accept: application/json
    Authorization: Bearer sdjhfskjdhkqy739459234
    备注

    You have to enter your own portal address to the Host: yourportal.onlyoffice.com line instead of yourportal.onlyoffice.com address.

Authentication request examples

const axios = require("axios");

async function authenticate() {
try {
const response = await axios.post("https://yourportal.onlyoffice.com/api/2.0/authentication", {
userName: "yourusername",
password: "yourpassword"
}, {
headers: {
"Content-Type": "application/json"
}
});

console.log(response.data);
} catch (error) {
console.error("Authentication failed:", error.response?.data || error.message);
}
}

authenticate();
备注

You have to enter your own portal address, username and password instead of yourportal.onlyoffice.com, yourusername and yourpassword respectively.