Overview of Authentication Modes

You are advised to use API-Key to authenticate HTTP interfaces related to the newly provided OpenAPI. However, against the previously providedfunction APIquery APIand some third-party interfaces can only be used“API_SECRET” or “Simulate login based on user name and password”to authenticate the HTTP interface.



API-Key authentication

The API-Key is a randomly generated 35-character text that is used as the user's identity when making HTTP requests. When a user assigns an API-Key to a specified project, the API-Key is bound to the user and project, and the binding relationship cannot be changed. The permissions of API-Key are the same as the permissions of the user to whom the API-Key is assigned. When the permissions of the user are adjusted, the permissions of API-Key also change.

API-Key getting


1. Click Project Settings → Basic Settings, and click "API Key Management" to enter the API-key management page.


2. If there is no API-key, click "Add Api Key" to create a new API-key. If the list already exists, copy the API-Key that has not expired directly.

Note: The API-Key displayed in the following list belongs to the "test project" associated with "Platform Administrator 1", and the API-Key can only be used under "Test Project" when sending HTTP requests;


Use of API-Key


Carry the API-Key in the query or header of the HTTP request, for example:api-key: #K-fMFGYYlot5H6dxxxxxxxxxxxxxxxxxxxxxx

Note that it is important to include project information in the query or header of the request, for example:sensorsdata-project: production

The following is an example of the complete curl command:

// 将 API-Key 作为 http header 进行传递; // 注意:由于 API-Key 是在项目下分配的,因此一个 API-Key 只能在一个项目下使用 curl -XGET "http://{host}:8107/api/v3/analytics/v1/project/list" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "sensorsdata-project: default" \ -H "api-key: {api-key}" // 如果需要以指定用户身份进行访问,可以通过在 headers 中指定 account-id 实现(注意:仅管理员的 API-Key 支持该用法) // 通过该方式访问接口时,该接口会以指定用户的身份执行,包括权限和操作日志等都会受到影响; curl -XGET "http://{host}:8107/api/v3/analytics/v1/project/list" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "sensorsdata-project: default" \ -H "api-key: {api-key}" \ -H "account-id: {account-id}"
CODE


More API-Key product documentation please refer to:API Key mangement