Create Fields
This text provides an example of how to call Create fields interface.
Example: create fields
Suppose you have a channel sales inventory summary table and you want to create a field in it.
Your action steps below:
Get your API Token.(How to get it)
Get your Space ID.(How to get it)
Get the ID of the datasheet.(How to get it)
Open the terminal on your computer and execute the following code to send a query request to the server (Assuming spaceId is
spcjXzqVrjaP3
,datasheetId isdstNiC6R9MryevVaCQ
) :- cURL
- Javascript SDK
- Python SDK
curl -X POST \
"https://aitable.ai/fusion/v1/spaces/spcjXzqVrjaP3/datasheets/dstNiC6R9MryevVaCQ/fields" \
-H "Authorization: Bearer {Your API Token}" \
-H 'Content-Type: application/json' \
-d '{
"type": "SingleText",
"name": "Title",
"property": {
"defaultValue": "Default value"
}
}'Note: Need to Download and initialize Javascript SDK first, and then execute the following command.
import { APITable } from 'apitable';
const apitable = new APITable({
token: 'Your API Token',
});
// Referring to IAddOpenFieldProperty, different FieldType corresponds to different Property structures
const property = {
defaultValue: 'Default value',
};
const fieldRo = {
name: 'New text field',
type: 'SingleText',
property,
};
try {
const res = await apitable.space('spcjXzqVrjaP3').datasheet('dstNiC6R9MryevVaCQ').fields.create(fieldRo);
if (res.success) {
// TODO: save field.id
}
} catch (error) {
// TODO: handle error
}Note: You need to download and initialize the Python SDK first, and then execute the following command.
from apitable import Apitable
apitable = Apitable("Your API Token")
prop = {
'defaultValue': 'Default value',
}
req_data = {
'name': 'New text field',
'type': 'SingleText',
'property': prop,
}
try:
field = apitable.space('spcjXzqVrjaP3').datasheet('dstNiC6R9MryevVaCQ').fields.create(req_data)
except Exception:
# Handling abnormal situations
passThe server returns the following JSON packets, below the
"data"
is all created fields:For the meaning of each parameter in the response, please check the API Reference
{
"success": true,
"code": 200,
"message": "SUCCESS",
"data": {
"id": "fldupsvkR2ATB",
"name": "Title"
}
}