Working with the Public API in DataLens On-premises

DataLens provides an API to automate operations with dashboards, charts, datasets, and connections.

The Public API offers methods similar to those used in the DataLens web interface. This API is described using the OpenAPI specification.

  • Swagger: http://<хост_on-premises>/api/docs/swagger
  • Methods: http://<хост_on-premises>/rpc/<method_name>

To get started with the DataLens API:

  1. The administrator must create a service account.

  2. The administrator creates a private key for the service account.

  3. The user signs a JWT using the private key. The maximum token lifetime is ten minutes.

    import jwt from 'jsonwebtoken';
    
    const signClientJwt = (
        saId: string,
        keyId: string,
        privateKey: string,
    ) => {
        const now = Math.floor(Date.now() / 1000);
        const payload = {
            iss: <service-account-id>,
            iat: now,
            exp: now + 300,
        };
        return jwt.sign(payload, <private-key>, {algorithm: 'PS256', keyid: <private-key-id>});
    };
    

    Where:

    • <service-account-id>: Service account ID.
    • <private-key-id>: Private key ID.
    • <private-key>: Private key.
  4. The user calls the http://<хост_on-premises>/rpc/exchangeServiceAccountToken method, exchanging the JWT for an API access token. The method returns a token you can use to call other API methods by specifying the token in the request header:

    --header "Authorization: Bearer <access-token>"
    

    Where <access-token> is the API access token.

    Note

    The maximum lifetime of an API access token is 15 minutes.