Skip to main content

Authentication and Authorization

Authentication and authorization are required when using the AskTable API to ensure that only authorized users and applications can access and manipulate data. This article will guide you through the process of authentication and authorization.

Authentication

Authentication is the process of verifying that a request comes from a legitimate user. When using the AskTable API, you need to provide an API-Key or a Temp-Token for authentication.

An API-Key is a secret key issued to applications to access the AskTable API. A Temp-Token is a temporary authentication token used to access the API for a certain period.

This document will provide detailed information on the use cases, acquisition methods, scenarios, and how to use API-Keys and Temp-Tokens for authentication and authorization.

API-Key

AskTable offers two different types of API-Keys for various access needs and permission control.

API-Key TypePurposeAcquisition MethodAPI List AvailableValidity Period
adminUsed to manage all resources within a project, with the highest permissions.Created through AskTable SaaSAll APIsLong-term
askerUsed for querying public data, suitable for public access scenarios.Created through AskTable SaaSSee belowLong-term

The list of APIs available for the asker API-Key:

API PathMethodDescription
/auth/meGETRetrieve information of the current authenticated user
/auth/tokensPOSTCreate new authentication tokens
/datasourcePOSTCreate a data source
/datasource/upload_filePOSTUpload a file
/single-turn/q2aPOSTInitiate a query request
/single-turn/q2sPOSTInitiate a request to generate SQL
/bots/<bot_id>GETRetrieve information of a specified bot
/chatsPOSTCreate a new chat session
/chats/<chat_id>GETRetrieve a specified chat session
/chats/<chat_id>/messagesGETRetrieve a list of messages for a specified chat
/chats/<chat_id>/messages/<message_id>GETQuery a specific message
/chats/<chat_id>DELETEDelete a specific chat (including messages)

Temp-Token

A Temp-Token is a temporary authentication token used for API access for a certain period. The Temp-Token is generated from an API-Key.

The API for generating a Temp-Token is as follows:

POST /auth/tokens
Content-Type: application/json
Authorization: Bearer <API_KEY>

{
"ak_role": "admin",
"chat_role": {
"role_id": "1",
"role_vars": {
"id": "42"
}
},
"user_profile": {
"name": "Zhang San"
},
"token_ttl": 900
}

Configuring Request Headers

In each request, you need to include the following information in the request headers:

  • Authorization: Bearer <Your API-Key or Temp-Token>
  • Content-Type: application/json

Here is an example using Python:

import requests

url = "https://api.asktable.com/v1/auth/me"
headers = {
"Authorization": "Bearer API_KEY_or_TEMP_TOKEN",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
print(response.json())

Error Handling

During the authentication and authorization process, you may encounter the following errors:

  • 401 Unauthorized: Indicates that the request has not been authenticated. Please check if your API-Key is correct.
  • 403 Forbidden: Indicates that the request has been denied access to the resource. Please check your role and policy configuration.

Next Steps

You now understand how to perform authentication and authorization. Proceed to read the Common Requests and Responses document for more detailed information.