---
metadata:
  - name: generator
    content: Diplodoc Platform v5.63.0
alternate:
  - en/datalens/operations/api-start.md
  - en/operations/api-start
  - ru/operations/api-start
  - href: en/operations/api-start.md
    type: text/markdown
    title: Markdown version
csp:
  - script-src:
      - https://mc.yandex.ru
    img-src:
      - https://mc.yandex.ru
    connect-src:
      - https://mc.yandex.ru
      - wss://mc.yandex.ru
    child-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-ancestors:
      - 'blob:'
      - https://mc.yandex.ru
canonical: en/operations/api-start.html
vcsPath: en/operations/api-start.md
---
# 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](../security/manage-service-accounts.md#create).
1. The administrator creates a [private key](../security/manage-service-accounts.md#add-key) for the service account.
1. The user signs a JWT using the private key. The maximum token lifetime is ten minutes.

    ```bash
    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.

1. 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:

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

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

    {% note info %}

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

    {% endnote %}

