### Install axios-miniprogram-adapter
Source: https://developers.aitable.ai/api/use-javascript-sdk-in-wechat-miniprogram
Install the adapter using yarn.
```bash
yarn add axios-miniprogram-adapter
```
--------------------------------
### Install Project Dependencies
Source: https://developers.aitable.ai/widget/widget-datasheet-operation
Navigate to the cloned project directory and install the necessary dependency libraries using npm.
```bash
cd widget-datasheet-operation
npm install
```
--------------------------------
### Get Fields
Source: https://developers.aitable.ai/api/field
This text provides an example of how to call Get fields interface.
```APIDOC
## Get Fields
### Description
This endpoint retrieves a list of fields.
### Method
GET
### Endpoint
/fields
```
--------------------------------
### Install Python SDK (Beta)
Source: https://developers.aitable.ai/api/fusion-api-v3
Install the beta version of the Python SDK to use Fusion API v3. This command installs version 2.0.0b4.
```bash
pip install apitable==2.0.0b4
```
--------------------------------
### Start Widget Development Mode
Source: https://developers.aitable.ai/widget/widget-datasheet-operation
Enter the development mode for your widget using the widget-cli start command. This allows for live preview and debugging.
```bash
widget-cli start
```
--------------------------------
### Install Javascript SDK (Beta)
Source: https://developers.aitable.ai/api/fusion-api-v3
Install the beta version of the Javascript SDK to use Fusion API v3. This command installs version 2.0.0-beta.4.
```bash
npm i apitable@2.0.0-beta.4
```
--------------------------------
### Python SDK Example
Source: https://developers.aitable.ai/api/create-chat-completions
This example demonstrates how to use the Python SDK to create chat completions. Make sure to set your API key and base URL.
```APIDOC
## Python SDK
### Description
Utilize the Python SDK for creating chat completions.
### Initialization
```python
import openai
openai.api_key = "_Paste_Your_API_Token_"
openai.api_base = "https://aitable.ai/nest/v1/ai/{AI_AGENT_ID}"
```
### Method Call
```python
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
```
```
--------------------------------
### Install AITable JavaScript SDK (npm)
Source: https://developers.aitable.ai/api/quick-start
Install the AITable JavaScript SDK using npm. Ensure you have npm installed on your system beforehand.
```bash
# You need to install npm in advance
npm install apitable@latest
```
--------------------------------
### Get Records with Filters and Sorting
Source: https://developers.aitable.ai/api/get-records
This example demonstrates how to fetch records using filters and customize the sorting order. It also shows the structure of the response, including pagination details.
```APIDOC
## Get Records
### Description
Retrieves a list of records based on specified filters and quantities, with customizable sorting.
### Method
GET
### Endpoint
`/api/v1/records`
### Query Parameters
- **filter** (string) - Optional - A JSON string representing the filter conditions.
- **pageSize** (integer) - Optional - The number of records to return per page.
- **pageNum** (integer) - Optional - The page number to retrieve.
- **sort** (string) - Optional - A JSON string defining the sorting order.
### Response
#### Success Response (200)
- **records** (array) - An array of record objects.
- **pageSize** (integer) - The number of records returned per page.
- **pageNum** (integer) - The current page number.
#### Response Example
```json
{
"records": [
{
"recordId": "recZ9ZLTXVFPc",
"createdAt": 1671589943000,
"updatedAt": 1671597856000,
"fields": {
"title": "Juice Cup",
"picture": [
{
"id": "atcbGfpA2Jc6O",
"name": "image.png",
"size": 3539,
"mimeType": "image/png",
"token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
"width": 48,
"height": 49,
"url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
}
],
"main selling points": [
"Vacuum",
"Push Button Type"
]
}
},
{
"recordId": "recZ9ZLTXVFPc",
"createdAt": 1671589943000,
"updatedAt": 1671597856000,
"fields": {
"original price": 149,
"promotion price": 129,
"inbound time": 1671589943382,
"title": "Electric heating water cup",
"picture": [
{
"id": "atcbGfpA2Jc6O",
"name": "image.png",
"size": 3539,
"mimeType": "image/png",
"token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
"width": 48,
"height": 49,
"url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
}
],
"main selling points": [
"Electric hot water bottle",
"Thermal insulation"
]
}
}
],
"pageSize": 3,
"pageNum": 1
}
```
```
--------------------------------
### Javascript SDK Example
Source: https://developers.aitable.ai/api/create-chat-completions
This example shows how to use the Javascript SDK to create chat completions. Ensure you have initialized the SDK with your API token and base path.
```APIDOC
## Javascript SDK
### Description
Use the Javascript SDK to interact with the chat completions API.
### Initialization
```javascript
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: "_Paste_Your_API_Token_",
basePath: "https://aitable.ai/fusion/v1/ai/{AI_AGENT_ID}"
});
const openai = new OpenAIApi(configuration);
```
### Method Call
```javascript
const chatCompletion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: "Hello world"}],
});
```
```
--------------------------------
### Install AITable JavaScript SDK (yarn)
Source: https://developers.aitable.ai/api/quick-start
Install the AITable JavaScript SDK using yarn. This method requires yarn to be installed on your system.
```bash
# You need to install yarn in advance
yarn add apitable@latest
```
--------------------------------
### Use officially provided SDK
Source: https://developers.aitable.ai/api/quick-start
The SDK (Sofware Development Kit, Software Development Toolkit) provides a cover for network requests and authentications, handles details on many API requests and helps you quickly start to experience AITable API. AITable SDK is officially provided on GitHub. Before using SDK, you need to execute the following commands on the terminal of the computer to install and initialize the SDK
```APIDOC
### Method 2: Use officially provided SDK
The SDK (Sofware Development Kit, Software Development Toolkit) provides a cover for network requests and authentications, handles details on many API requests and helps you quickly start to experience AITable API. AITable SDK is officially provided on GitHub. Before using SDK, you need to execute the following commands on the terminal of the computer to install and initialize the SDK
* Javascript SDK
* Python SDK
1. Install the Javascript SDK by either of the following methods.
* npm
* yarn
```bash
# You need to install npm in advance
npm install apitable@latest
```
```bash
# You need to install yarn in advance
yarn add apitable@latest
```
2. Initialize the Javascript SDK.
```javascript
import { APITable } from "apitable";
const apitable = new APITable({ token: "_Your_API_Token_"});
```
When instantiating the SDK client you have the option to configure the following global parameters.
Options| Type| Default value| Description
---|---|---|---
token| string| | Required, representing the incoming API Token
fieldKey| string| name| The key used to query and return fields.By default use `name`(field name).When specified as `id`, fieldId will be used as the query and return method (using `id` can avoid code failure due to modifying the field name)
requestTimeout| number| 60000| Request expiration time, milliseconds, default value is 6000000 (i. e. 10 seconds)
host| string| `https://aitable.ai/fusion/v1`| Destination server
adapter| any| | If it needs to be used in the WeChat Miniprogram, a request adapter needs to be added, see Using Vika JS SDK in the WeChat Miniprogram
1. Install Python SDK.
```bash
# Python version needs to be v3.6 or above
# Need to install pip in advance
pip install --upgrade apitable
```
2. Initialize the Python SDK.
```python
from apitable import Apitable
apitable = Apitable("_Your_API_Token_")
```
Once the request is determined, you can write the code, calling the corresponding APItable API interface.
```
--------------------------------
### Get Records with Filters and Sorting
Source: https://developers.aitable.ai/api/get-records
This example demonstrates how to retrieve records based on specified filters and quantities, with custom sorting applied. It shows the structure of the response, including record details and pagination information.
```json
{
"data": [
{
"recordId": "recZ9ZLTXVFPc",
"createdAt": 1671589943000,
"updatedAt": 1671597856000,
"fields": {
"title": "Juice Cup",
"picture": [
{
"id": "atcbGfpA2Jc6O",
"name": "image.png",
"size": 3539,
"mimeType": "image/png",
"token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
"width": 48,
"height": 49,
"url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
}
],
"main selling points": [
"Vacuum",
"Push Button Type"
]
}
},
{
"recordId": "recZ9ZLTXVFPc",
"createdAt": 1671589943000,
"updatedAt": 1671597856000,
"fields": {
"original price": 149,
"promotion price": 129,
"inbound time": 1671589943382,
"title": "Electric heating water cup",
"picture": [
{
"id": "atcbGfpA2Jc6O",
"name": "image.png",
"size": 3539,
"mimeType": "image/png",
"token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
"width": 48,
"height": 49,
"url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
}
],
"main selling points": [
"Electric hot water bottle",
"Thermal insulation"
]
}
}
],
"pageSize": 3,
"pageNum": 1,
"message": "SUCCESS"
}
```
--------------------------------
### cURL Example
Source: https://developers.aitable.ai/api/create-chat-completions
This example demonstrates how to call the Create chat completions API using cURL. Replace `{Your API Token}` with your actual API token and `ai_zxLeHGV3ac32YYC` with your AI agent ID.
```APIDOC
## POST /chat/completions
### Description
This endpoint allows you to create chat completions by sending a POST request with model and messages.
### Method
POST
### Endpoint
`https://aitable.ai/fusion/ai/{AI_AGENT_ID}/chat/completions`
### Parameters
#### Headers
- **Authorization** (string) - Required - Bearer token for authentication.
- **Content-Type** (string) - Required - `application/json`
#### Request Body
- **model** (string) - Required - The model to use for chat completions (e.g., `gpt-3.5-turbo`).
- **messages** (array) - Required - An array of message objects, each with a `role` (system, user, or assistant) and `content`.
### Request Example
```json
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
```
### Response
#### Success Response (200)
- **id** (string) - Unique identifier for the completion.
- **conversation id** (string) - Identifier for the conversation.
- **actions** (any) - Placeholder for actions, currently null.
- **object** (string) - Type of the object, e.g., `chat.completion`.
- **created** (integer) - Timestamp of creation.
- **model** (string) - The model used for the completion.
- **choices** (array) - An array of completion choices.
- **index** (integer) - Index of the choice.
- **message** (object) - The message content from the assistant.
- **role** (string) - Role of the message sender (e.g., `assistant`).
- **content** (string) - The assistant's reply.
- **finish_reason** (string) - The reason the model stopped generating tokens (e.g., `stop`).
- **usage** (object) - Token usage statistics.
- **prompt_tokens** (integer) - Number of tokens in the prompt.
- **completion_tokens** (integer) - Number of tokens in the completion.
- **total_tokens** (integer) - Total tokens used.
- **total cost** (number) - Total cost of the completion.
- **result** (string) - A summary or result from the model.
### Response Example
```json
{
"id": "aitable_ai_CkZH2zQokhry31j_1693452659",
"conversation id": "CS-0253eb8d-d6c6-4543-88d4-fcb555f52982",
"actions": null,
"object": "chat.completion",
"created": 1693452659,
"model":"gpt-3.5-turbo",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today",
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21,
"total cost": 7.900000000000001e-05,
"result": "I am an AI, specifically a language model developed by OpenAI."
}
}
```
```
--------------------------------
### Authentication Example
Source: https://developers.aitable.ai/api/reference/api/openapi
This example demonstrates how to authenticate API requests using an API token by including it in the Authorization header.
```APIDOC
## Authentication
### Way 1: By API token
API Token is the user authentication token. When you send an API request to the AITable server, you must include `Authorization: Bearer {Your API Token}` in the request header to facilitate the server's authentication of the user's identity.
```bash
curl "https://aitable.ai/fusion/v1/datasheets/{datasheetId}/records" \
-H "Authorization: Bearer {Your API Token}" \
```
Its request header includes:
| Name | Data Type | Required | Format of Value | Example Value |
|----------------|-------------|----------|-------------------------|-----------------------|
| Authorization | String | Yes | `Bearer {Your API Token}` | `Bearer uskYtInkHozfsMikhh0yfoS` |
```
--------------------------------
### Get Fields Request (JavaScript)
Source: https://developers.aitable.ai/api/reference
Example JavaScript SDK request to retrieve all fields from a specified datasheet. Replace placeholders with your actual datasheet ID and API token.
```javascript
fetch('https://aitable.ai/fusion/v1/datasheets/{datasheetId}/fields', {
method: 'GET',
headers: {
'Authorization': 'Bearer {your API Token}'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```
--------------------------------
### Horizontal Alignment Example
Source: https://developers.aitable.ai/widget/components/space
Demonstrates horizontal alignment options ('start', 'center', 'end', 'baseline') for child elements within the Space component.
```jsx
text
button
box
text
button
box
text
button
box
text
button
box
```
--------------------------------
### Create a Team API Example
Source: https://developers.aitable.ai/api/create-a-team
This example demonstrates how to create a new team using the Create a Team API. It includes the necessary cURL command, request body, and expected response.
```APIDOC
## POST /spaces/{spaceId}/teams
### Description
Creates a new team within a specified space.
### Method
POST
### Endpoint
/spaces/{spaceId}/teams
### Parameters
#### Path Parameters
- **spaceId** (string) - Required - The ID of the space where the team will be created.
#### Request Body
- **name** (string) - Required - The name of the new team.
- **sequence** (integer) - Optional - The sequence number for the team.
- **parentUnitId** (string) - Required - The unit ID of the parent team.
- **roles** (array of strings) - Optional - A list of role unit IDs to associate with the team.
### Request Example
```json
{
"name":"Product Team",
"sequence":1,
"parentUnitId":"eJ6mP5SbW8hF2Zl4YxRrXyKwDzQcTnN",
"roles":["bY5nKzT4LrJpHsN3jG7fW2mVcXvq8xQ"]
}
```
### Response
#### Success Response (200)
- **data.team.unitId** (string) - The unique identifier of the newly created team.
- **data.team.name** (string) - The name of the newly created team.
- **data.team.sequence** (integer) - The sequence number of the team.
- **data.team.parentUnitId** (string) - The unit ID of the parent team.
- **data.team.roles** (array of objects) - A list of roles associated with the team, each with `unitId`, `name`, and `sequence`.
#### Response Example
```json
{
"code": 200,
"message": "SUCCESS",
"success": true,
"data": {
"team": {
"unitId": "T6dCwJ9zUxYfKpV2kNvMmGtXqL1sHrS",
"name": "Product Team",
"sequence": 1,
"parentUnitId": "eJ6mP5SbW8hF2Zl4YxRrXyKwDzQcTnN",
"roles": [
{
"unitId": "bY5nKzT4LrJpHsN3jG7fW2mVcXvq8xQ",
"name": "Product Designer",
"sequence": 1
}
]
}
}
}
```
```
--------------------------------
### Install AITable Python SDK
Source: https://developers.aitable.ai/api/quick-start
Install the AITable Python SDK using pip. This requires Python version 3.6 or above and pip to be installed.
```bash
# Python version needs to be v3.6 or above
# Need to install pip in advance
pip install --upgrade apitable
```
--------------------------------
### Design Token Interaction Examples
Source: https://developers.aitable.ai/widget/design-tokens
Examples demonstrating the optional 'interaction' parameter, which specifies states like hover, active, or disabled for tokens.
```css
--bg-brand-active
```
```css
--text-link-hover
```
--------------------------------
### Design Token Type Examples
Source: https://developers.aitable.ai/widget/design-tokens
Examples demonstrating the 'type' component of design tokens, specifying background (bg), text/icon (text), border, and shadow.
```css
--bg-common-default
```
```css
--text-common-primary
```
--------------------------------
### Install Widget CLI Globally
Source: https://developers.aitable.ai/widget/widget-datasheet-operation
Install the Aitable Widget CLI globally if this is your first time developing a widget. This tool is necessary for creating and managing widgets.
```bash
npm install -g @apitable/widget-cli
```
--------------------------------
### Get Records with Filters and Sorting
Source: https://developers.aitable.ai/api/get-records
This example demonstrates how to retrieve records that match specific criteria, such as keywords in a field, and sort them by a particular field in descending order. It shows the usage of `filterByFormula`, `maxRecords`, and `sort` parameters.
```APIDOC
## GET /datasheets/{datasheetId}/records
### Description
Retrieves records from a datasheet based on provided filters and sorting preferences.
### Method
GET
### Endpoint
`/datasheets/{datasheetId}/records`
### Query Parameters
- **filterByFormula** (string) - Required - A formula to filter records. Example: `OR(find("Vacuum", {main selling point}) > 0, find("Thermal insulation", {main selling point}) > 0)`
- **maxRecords** (integer) - Optional - The maximum number of records to return. Example: `3`
- **sort** (object) - Optional - An object specifying the field and order for sorting. Example: `{"field": "promotion price", "order": "desc"}`
### Request Example (cURL)
```bash
curl -X GET \
'https://aitable.ai/fusion/v1/datasheets/dstNrmvismEKLSMn2Q/records?filterByFormula=OR(find("Vacuum", {main selling Points}) > 0, find("Thermal insulation", {main selling points}) > 0)&maxRecords=3&sort={"field": "promotion price", "order": "desc"}' \
-H "Authorization: Bearer {Your API Token}"
```
### Response
#### Success Response (200)
- **code** (integer) - The status code of the response.
- **success** (boolean) - Indicates if the request was successful.
- **data** (object) - Contains the retrieved records and total count.
- **total** (integer) - The total number of records matching the query.
- **records** (array) - An array of record objects.
- **recordId** (string) - The unique identifier for the record.
- **createdAt** (integer) - Timestamp when the record was created.
- **updatedAt** (integer) - Timestamp when the record was last updated.
- **fields** (object) - An object containing the fields and their values for the record.
#### Response Example
```json
{
"code": 200,
"success": true,
"data": {
"total": 3,
"records": [
{
"recordId": "recX1UxK12bIo",
"createdAt": 1671589943000,
"updatedAt": 1671597856000,
"fields": {
"original price": 399,
"promotion price": 369,
"inbound time": 1671589943382,
"title": "Life multifunctional cup",
"picture": [
{
"id": "atcbGfpA2Jc6O",
"name": "image.png",
"size": 3539,
"mimeType": "image/png",
"token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
"width": 48,
"height": 49,
"url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
}
],
"main selling points": [
"High-borosilicate glass",
"Cook",
"Thermal insulation"
]
}
}
]
}
}
```
```
--------------------------------
### Install Widget Development Tool
Source: https://developers.aitable.ai/widget/quick-start
Execute this command in your terminal to install the AITable widget command-line interface globally. This tool is essential for initializing and managing your widget development.
```bash
npm install -g @apitable/widget-cli
```
--------------------------------
### Design Token Prominence Examples
Source: https://developers.aitable.ai/widget/design-tokens
Examples showing the optional 'prominence' parameter, used to establish visual hierarchy with levels like Level 1, Level 2, etc.
```css
--text-common-secondary
```
```css
--bg-common-lowest
```
--------------------------------
### Launch Widget Development Server
Source: https://developers.aitable.ai/widget/quick-start
Run this command in your project's root directory to start the local development server. This enables live previewing and debugging of your widget.
```bash
widget-cli start
```
--------------------------------
### API Response for Get Views
Source: https://developers.aitable.ai/api/get-views
This is an example of the JSON response received after successfully calling the Get Views API. It includes a list of all views with their respective IDs, names, and types.
```json
{
"code": 200,
"success": true,
"data": {
"views": [
{
"id": "viwBBD0FJmGgl",
"name": "Grid view",
"type": "Grid"
},
{
"id": "viwHikMoyvm3U",
"name": "Gallery",
"type": "Gallery"
},
{
"id": "viwZbTXzYeLOm",
"name": "Brand Grouping",
"type": "Grid"
},
{
"id": "viwi88msbLv50",
"name": "Kanban",
"type": "Kanban"
},
{
"id": "viwWwIQcQKdKw",
"name": "Gantt",
"type": "Gantt"
}
]
},
"message": "SUCCESS"
}
```
--------------------------------
### Get Outermost Nodes List (JavaScript SDK)
Source: https://developers.aitable.ai/api/get-nodes
This JavaScript SDK example demonstrates how to get the first-level file directory of a specified space. It also shows how to recursively get child nodes if a node is a folder. Ensure you have downloaded and initialized the Javascript SDK.
```javascript
import { APITable } from 'apitable';
const apitable = new APITable({
token: 'Your API Token',
});
// Get the first-level file directory of the specified space
const nodeListResp = await apitable.nodes.list({spaceId: 'spcX9P2xUcKst'})
if (nodeListResp.success) {
console.log(nodeListResp.data.nodes);
const nodes = nodeListResp.data.nodes
nodes.forEach(node=> {
// When the node is a folder, you can execute the following code to get information about the files under the folder
if (node.type === 'Folder') {
const folderDetailResp = await apitable.nodes.list({spaceId: 'spcX9P2xUcKst', nodeId: node.id})
if (folderDetailResp.success){
// Print the child nodes under the folder
console.log(folderDetailResp.data.children)
}
}
})
} else {
console.error(nodeListResp);
}
```
--------------------------------
### Get all views of a specified datasheet
Source: https://developers.aitable.ai/api/get-views
This example demonstrates how to retrieve all views for a given datasheet using its ID.
```APIDOC
## GET /fusion/v1/datasheets/{datasheetId}/views
### Description
Retrieves all views associated with a specific datasheet.
### Method
GET
### Endpoint
/fusion/v1/datasheets/{datasheetId}/views
### Parameters
#### Path Parameters
- **datasheetId** (string) - Required - The ID of the datasheet.
#### Request Headers
- **Authorization** (string) - Required - Bearer token for authentication.
### Response
#### Success Response (200)
- **code** (integer) - The status code of the response.
- **success** (boolean) - Indicates if the request was successful.
- **data** (object) - Contains the view data.
- **views** (array) - An array of view objects.
- **id** (string) - The unique identifier for the view.
- **name** (string) - The name of the view.
- **type** (string) - The type of the view (e.g., Grid, Gallery, Kanban, Gantt).
- **message** (string) - A message indicating the status of the response.
### Request Example
```bash
curl -X GET \
"https://aitable.ai/fusion/v1/datasheets/dst0vPx2577RdMN9MC/views" \
-H "Authorization: Bearer {Your API Token}"
```
### Response Example
```json
{
"code": 200,
"success": true,
"data": {
"views": [
{
"id": "viwBBD0FJmGgl",
"name": "Grid view",
"type": "Grid"
},
{
"id": "viwHikMoyvm3U",
"name": "Gallery",
"type": "Gallery"
},
{
"id": "viwZbTXzYeLOm",
"name": "Brand Grouping",
"type": "Grid"
},
{
"id": "viwi88msbLv50",
"name": "Kanban",
"type": "Kanban"
},
{
"id": "viwWwIQcQKdKw",
"name": "Gantt",
"type": "Gantt"
}
]
},
"message": "SUCCESS"
}
```
```
```javascript
import { APITable } from 'apitable';
const apitable = new APITable({
token: 'Your API Token',
});
const datasheet = apitable.datasheet("dst0vPx2577RdMN9MC");
const viewsResp = await datasheet.views.list()
if (viewsResp.success) {
console.log(viewsResp.data.views);
} else {
console.error(viewsResp);
}
```
```python
from apitable import Apitable
apitable = Apitable("Your API Token")
dst = apitable.datasheet("dst0vPx2577RdMN9MC")
views = dst.views.all()
for view in views:
print(view.json())
```
--------------------------------
### Get Node List using Javascript SDK
Source: https://developers.aitable.ai/api/get-nodes
This example shows how to use the Javascript SDK to get the list of outermost nodes in a space. It also includes logic to fetch details of child nodes if a node is a folder.
```APIDOC
## apitable.nodes.list({spaceId})
### Description
This method from the Javascript SDK retrieves the first-level file directory of the specified space.
### Method Signature
`apitable.nodes.list({spaceId: 'string'})`
### Parameters
#### Input Parameters
- **spaceId** (string) - Required - The ID of the space to retrieve nodes from.
### Request Example
```javascript
import { APITable } from 'apitable';
const apitable = new APITable({
token: 'Your API Token',
});
// Get the first-level file directory of the specified space
const nodeListResp = await apitable.nodes.list({spaceId: 'spcX9P2xUcKst'})
if (nodeListResp.success) {
console.log(nodeListResp.data.nodes);
const nodes = nodeListResp.data.nodes;
nodes.forEach(node => {
// When the node is a folder, you can execute the following code to get information about the files under the folder
if (node.type === 'Folder') {
const folderDetailResp = await apitable.nodes.get({spaceId: 'spcX9P2xUcKst', nodeId: node.id})
if (folderDetailResp.success){
// Print the child nodes under the folder
console.log(folderDetailResp.data.children)
}
}
})
} else {
console.error(nodeListResp);
}
```
### Response
#### Success Response
The response object contains a `success` boolean, `data` object, and `message` string. The `data` object contains a `nodes` array, where each element represents a node with properties like `id`, `name`, `type`, `icon`, and `isFav`.
#### Response Example
```json
{
"success": true,
"data": {
"nodes": [
{
"id": "fom680eghkCem0wZxk",
"name": "New Form",
"type": "Form",
"icon": "",
"isFav": false
}
// ... more nodes
]
},
"message": "SUCCESS"
}
```
```
--------------------------------
### API Response Structure for Get Node List
Source: https://developers.aitable.ai/api/get-nodes
This is an example of the JSON response structure returned by the Get Node List API. It includes a list of nodes, each with properties like id, name, type, icon, and isFav.
```json
{
"code": 200,
"success": true,
"data": {
"nodes": [
{
"id": "fom680eghkCem0wZxk",
"name": "New Form",
"type": "Form",
"icon": "",
"isFav": false
},
{
"id": "dsbWxTei5gdTvdAfKM",
"name": "New Dashboard",
"type": "Dashboard",
"icon": "",
"isFav": false
},
{
"id": "fod23ha5NvyM5",
"name": "New Folder",
"type": "Folder",
"icon": "",
"isFav": false
},
{
"id": "dstZsEg3RpBvsdCgop",
"name": "test-specific-template3",
"type": "Datasheet",
"icon": "",
"isFav": true
}
]
},
"message": "SUCCESS"
}
```
--------------------------------
### Get all fields of a specified datasheet
Source: https://developers.aitable.ai/api/get-fields
This example demonstrates how to retrieve all fields from a datasheet using its ID. It includes instructions for obtaining an API token and datasheet ID, and provides code examples for cURL, Javascript SDK, and Python SDK.
```APIDOC
## GET /fusion/v1/datasheets/{datasheetId}/fields
### Description
Retrieves all fields associated with a specific datasheet.
### Method
GET
### Endpoint
`/fusion/v1/datasheets/{datasheetId}/fields`
### Parameters
#### Path Parameters
- **datasheetId** (string) - Required - The ID of the datasheet.
#### Headers
- **Authorization** (string) - Required - Bearer token for authentication. Format: `Bearer {Your API Token}`
### Request Example
```bash
curl -X GET \
"https://aitable.ai/fusion/v1/datasheets/dstCufZ779fE41TzZy/fields" \
-H "Authorization: Bearer {Your API Token}"
```
### Response
#### Success Response (200)
- **code** (integer) - The status code of the response.
- **success** (boolean) - Indicates if the request was successful.
- **data** (object) - Contains the field data.
- **fields** (array) - An array of field objects.
- **id** (string) - The unique identifier for the field.
- **name** (string) - The name of the field.
- **type** (string) - The data type of the field (e.g., "SingleText", "SingleSelect").
- **property** (object) - Field-specific properties (e.g., "defaultValue", "options").
- **editable** (boolean) - Indicates if the field is editable.
- **isPrimary** (boolean, optional) - Indicates if the field is the primary field.
- **message** (string) - A message indicating the status of the response.
#### Response Example
```json
{
"code": 200,
"success": true,
"data": {
"fields": [
{
"id": "fldGMxxBjVzGi",
"name": "Product UPC",
"type": "SingleText",
"property": {
"defaultValue": ""
},
"editable": true,
"isPrimary": true
},
{
"id": "fldlSvMaP5TQG",
"name": "SKU name",
"type": "SingleText",
"property": {},
"editable": true
},
{
"id": "fldlXCBJyXTPo",
"name": "Brands",
"type": "SingleSelect",
"property": {
"options": [
{
"id": "optCe7DGNgtkS",
"name": "OAD",
"color": {
"name": "deepPurple_0",
"value": "#E5E1FC"
}
},
{
"id": "optdgOCPhHToc",
"name": "Elevit",
"color": {
"name": "indigo_0",
"value": "#DDE7FF"
}
}
]
},
"editable": true
}
]
},
"message": "SUCCESS"
}
```
```
```javascript
import { APITable } from 'apitable';
const apitable = new APITable({
token: 'Your API Token',
});
const datasheet = apitable.datasheet("dstCufZ779fE41TzZy");
const fieldsResp = await datasheet.fields.list()
if (fieldsResp.success) {
console.log(fieldsResp.data.fields);
} else {
console.error(fieldsResp);
}
```
```python
from apitable import Apitable
apitable = Apitable("Your API Token")
dst = apitable.datasheet("dstCufZ779fE41TzZy")
# Get all fields
fields = dst.fields.all()
for field in fields:
print(field.json())
```
--------------------------------
### Reference Code for Mini Program (Taro Framework)
Source: https://developers.aitable.ai/api/use-javascript-sdk-in-wechat-miniprogram
This is a basic code example for a Mini Program using the Taro framework. It initializes the AITable SDK with the adapter and queries records upon component mount.
```javascript
import { Component } from 'react'
import { View, Text, Button } from '@tarojs/components'
import AITable from 'apitable';
import Taro from '@tarojs/taro';
import mpAdapter from 'axios-miniprogram-adapter';
import './index.less';
export default class Index extends Component {
componentWillMount() { }
componentDidMount() {
const apitable = new APITable({
token: 'your_api_token',
adapter: mpAdapter,
});
apitable.datasheet('dstxJZ2xZXJnXScxxx').records.query().then(resp => {
console.log(resp.data?.records)
})
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
return (
Hello AITable!
)
}
}
```
--------------------------------
### Get Active Cell Value with useActiveCell
Source: https://developers.aitable.ai/widget/api-reference/modules/hooks_use_active_cell
Use this hook to get the value of the currently active cell. Ensure you handle cases where no cell is active. This example also uses `useRecord` to fetch the record associated with the active cell.
```javascript
import { useActiveCell, useRecord } from '@apitable/widget-sdk';
// Render the value of currently selected cell
function ActiveCell() {
const activeCell = useActiveCell();
const activeRecord = useRecord(activeCell?.recordId);
if (!activeCell || !activeRecord) {
return
Cells without activation
}
return Activated Cells: {activeRecord.getCellValueString(activeCell.fieldId)}
}
```
--------------------------------
### Vertical Alignment Example
Source: https://developers.aitable.ai/widget/components/space
Illustrates vertical alignment options ('start', 'center', 'end') for child elements when using column layout.
```jsx
text
button
box
text
button
box
text
button
box
```
--------------------------------
### Get Fields Request (cURL)
Source: https://developers.aitable.ai/api/reference
Example cURL request to retrieve all fields from a specified datasheet. Ensure to include your API token in the Authorization header.
```bash
curl -X GET \
'https://aitable.ai/fusion/v1/datasheets/{datasheetId}/fields' \
-H 'Authorization: Bearer {your API Token}'
```
--------------------------------
### Basic List Example
Source: https://developers.aitable.ai/widget/components/list
Demonstrates the default appearance of the List component. No special props are required for basic usage.
```javascript
list 1
list 2
list 3
list 4
list 5
```
--------------------------------
### Get all records in the specified view under the specified datasheet
Source: https://developers.aitable.ai/api/get-records
This example demonstrates how to retrieve all records from a specific view within a datasheet. It shows a sample successful response structure.
```APIDOC
## Get all records in the specified view under the specified datasheet
### Description
Retrieves all records from a specified view within a datasheet.
### Response
#### Success Response (200)
- **records** (array) - An array of record objects.
- **message** (string) - The status message, typically "SUCCESS".
### Response Example
```json
{
"data": {
"records": [
{
"body_length": 1.4,
"creator": {
"id": "defa8eadd75648cca0a0125c2f9445c9",
"unitId": "*********",
```