產品指南
基礎
自動化指南
集成指南
AI應用與模板指南
Open API
功能參考
自動化觸發器
自動化執行器
第三方集成
節點資源
數據表視圖
數據表字段
儀表板組件
智能任務
AI 向導
公式
空間站
更新日誌
Videos

title: OpenAPI Quick Start slug: help/en/guide/developer/openapi sidebar_position: 10 sidebar_label: Quick Start

OpenAPI Quick Start

Welcome to the Bika.ai OpenAPI Quick Start Guide!

This document provides a series of examples to help you get started with the Bika.ai API and SDK. Each section contains code snippets for common operations, including fetching data, creating records, updating records, deleting records, and using automation.

Basic Concepts

Before using this Open API, we need to first understand the structure and object hierarchy of Bika.ai.

  • Space
    • Node Resources:
      • Database
      • Automation
      • Dashboard
      • Document
      • AI Chatbot
      • ……

The Space is your workspace. It encompasses all the node resources we've previously mentioned, including databases, automation facilities, dashboards, and additional components. When leveraging the Open API, data retrieval must be carried out in accordance with this structure.

For instance, if you aim to obtain the database C represented by node B within Space A, the API would be similar to spaceA.nodeB->resoure->databaseB.

Note that the node ID is equivalent to the resource ID; for instance, Node ID and Database ID are the same.

For a URL like:

https://bika.ai/space/spcND68gdMMZBmGK67gvqNVX/node/datJubyEnetNFd3UQ6gSeq7U/viwYHuzUxRngq5igMkw9PPIX

SpaceId: spcND68gdMMZBmGK67gvqNVX

NodeID = DatabaseID: datJubyEnetNFd3UQ6gSeq7U

The associated TypeScript SDK is designed in an object-oriented style, which greatly simplifies your code.

Also, the space UI follows the above data structure layer.

For details, please read the homepage of the help document at https://bika.ai/help to view the overall UI introduction of the Space.

cURL

OpenAPI is composed of the HTTP protocol, and below are examples of how to call Bika.ai's OpenAPI using the cURL command line tool.

Please checkout the Bika.ai API Reference for more API details.

You can access these OpenAPI endpoints using any HTTP client that supports them, such as cURL, Python Requests, Node.js axios, Rust reqwest, and others.

Retrieving System Meta Info

curl -X GET "https://bika.ai/api/openapi/bika/v1/system/meta" -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"

Response Example:

{
    "success": true,
    "code": 200,
    "message": "SUCCESS",
    "data": {
        "version": "1.0.0-release.0",
        "appEnv": "PRODUCTION",
        "hostname": "https://bika.ai",
        "headers": {
            "X-Forwarded-For": "35.96.5.64",
            "User-Agent": "curl/8.4.0"
        }
    }
}

Retrieving Space List

curl -X GET "https://bika.ai/api/openapi/bika/v1/spaces" -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"

Creating a New Record

Assume we have obtained the ID of a certain space as {SPACE_ID}, node ID as {NODE_ID}, and database ID always equals to node ID. Here is an example of creating a new record:

curl -X POST "https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/resources/databases/{NODE_ID}/records" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
    -H "Content-Type: application/json" \
    -d '{
        "cells": {
            "Name": "New record",
            "Description": "This is a new database record"
        }
    }'

Updating a Record

Assume the record ID is {RECORD_ID}. The example of updating a record is as follows:

curl -X PATCH "https://bika.ai/api/openapi/bika/v1/spaces/spcpPuRJJC4CZOwzB9Vlwmja/resources/databases/datkW11Rxx6hFJO924ECNxLk/records" \
    -H "Authorization: Bearer bkteM550dHdXyTKN4Wkp59pYX8JD5cDU7rB" \
    -H "Content-Type: application/json" \
    -d '{
        "id": "recpx8ZUBHmRFuD0fGTObHxL",
        "cells": {
            "Task": "Updated description field column"
        }
    }'

Deleting a Record

curl -X DELETE "https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/resources/databases/{NODE_ID}/records/{RECORD_ID}" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"

Listing Automation Triggers

Assume the node ID is {NODE_ID}. The example is as follows:

curl -X GET "https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/resources/automation/{NODE_ID}/triggers" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"

Registering an Outbound Webhook

curl -X POST "https://bika.ai/api/openapi/bika/v1/spaces/{SPACE_ID}/outgoing-webhooks" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
    -H "Content-Type: application/json" \
    -d '{
        "eventType": "ON_RECORD_CREATED",
        "name": "Create webhook",
        "description": "Example trigger when a new record is created",
        "callbackURL": "https://your - custom - callback - url.com"
    }'

Python HTTP Client

Installing Dependencies

First, ensure that the requests library is installed. You can use the following command to install it:

pip install requests

Retrieving System Metadata

import requests

access_token = "{YOUR_ACCESS_TOKEN}"
url = "https://bika.ai/api/openapi/bika/v1/system/meta"
headers = {
    "Authorization": f"Bearer {access_token}"
}
response = requests.get(url, headers = headers)
print(response.json())

Retrieving Space List

import requests

access_token = "{YOUR_ACCESS_TOKEN}"
url = "https://bika.ai/api/openapi/bika/v1/spaces"
headers = {
    "Authorization": f"Bearer {access_token}"
}
response = requests.get(url, headers = headers)
spaces = response.json()["data"]
print(spaces)

Retrieving Database Records

import requests
import json

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
node_id = "{NODE_ID}"
database_id = "{DATABASE_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/resources/databases/{node_id}/records"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
data = {
    "fields": {
        "Name": "New record",
        "Description": "This is a new database record"
    }
}
response = requests.post(url, headers = headers, data = json.dumps(data))
print(response.json())

Creating a New Record

import requests
import json

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
node_id = "{NODE_ID}"
database_id = "{DATABASE_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/resources/databases/{node_id}/records"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
data = {
    "cells": {
        "Name": "New record",
        "Description": "This is a new database record"
    }
}
response = requests.post(url, headers = headers, data = json.dumps(data))
print(response.json())

Updating a Record

import requests
import json

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
node_id = "{NODE_ID}"
database_id = "{DATABASE_ID}"
record_id = "{RECORD_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/resources/databases/{node_id}/records"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
data = {
    "id": "recpx8ZUBHmRFuD0fGTObHxL",
    "cells": {
        "Task": "Updated description field column"
    }
}
response = requests.patch(url, headers = headers, data = json.dumps(data))
print(response.json())

Deleting a Record

import requests

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
node_id = "{NODE_ID_DATABASE_ID}"
record_id = "{RECORD_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/resources/databases/{node_id}/records/{record_id}"
headers = {
    "Authorization": f"Bearer {access_token}"
}
response = requests.delete(url, headers = headers)
print(response.json())

Listing Automation Triggers

import requests

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
node_id = "{NODE_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/nodes/{node_id}/automation/triggers"
headers = {
    "Authorization": f"Bearer {access_token}"
}
response = requests.get(url, headers = headers)
triggers = response.json()["data"]
print(triggers)

Registering an Outbound Webhook

import requests
import json

access_token = "{YOUR_ACCESS_TOKEN}"
space_id = "{SPACE_ID}"
url = f"https://bika.ai/api/openapi/bika/v1/spaces/{space_id}/outgoing-webhooks"
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}
data = {
    "eventType": "ON_RECORD_CREATED",
    "name": "Create webhook",
    "description": "Example trigger when a new record is created",
    "callbackURL": "https://your - custom - callback - url.com"
}
response = requests.post(url, headers = headers, data = json.dumps(data))
print(response.json())

Through the above cURL and Python examples, developers can more conveniently use the Bika.ai OpenAPI to perform various operations. For more detailed information, please refer to the Bika.ai API documentation.

TypeScript / JavaScript SDK

Bika.ai offers an official TypeScript/JavaScript SDK for convenient object-oriented programming when using Bika.ai's OpenAPI.

Prerequisites

  1. Node.js installed on your machine.
  2. Bika.ai API Token: Sign up on Bika.ai and get your API token from your user settings.

Installation

First, install the Bika.ai SDK using npm:

npm install bika.ai
# or
yarn add bika.ai
pnpm add bika.ai

Example 1: Fetch Database Records

This example demonstrates how to fetch spaces, nodes, and records.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async <em>function</em> fetchRecords() {
    try {
        <em>const</em> spaces = await bika.space.list();
        <em>const</em> space = spaces[0];
        <em>const</em> nodes = await space.nodes.list();
        <em>const</em> node = nodes.find((<em>node</em>) <em>=></em> <em>node</em>.resourceType === 'DATABASE');
        <em>const</em> database = await node?.asDatabase();
        <em>const</em> records = await database?.records.list();
        console.log('Records:', records);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}

fetchRecords();

Example 2: Create a New Record

Use this example to create a new record in your database.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async <em>function</em> createRecord() {
    try {
        <em>const</em> spaces = await bika.space.list();
        <em>const</em> space = spaces[0];
        <em>const</em> nodes = await space.nodes.list();
        <em>const</em> node = nodes.find((<em>node</em>) <em>=></em> <em>node</em>.resourceType === 'DATABASE');
        <em>const</em> database = await node?.asDatabase();
        <em>const</em> newRecord = await database?.records.create({
            cells: {
                Name: 'New record',
            },
        });

        console.log('New Record Created:', newRecord);
    } catch (error) {
        console.error('Error creating record:', error);
    }
}
createRecord();

Example 3: Update a Record

This example updates an existing record.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async <em>function</em> updateRecord(<em>recordId</em>: <em>string</em>) {
    try {
        <em>const</em> spaces = await bika.space.list();
        <em>const</em> space = spaces[0];
        <em>const</em> nodes = await space.nodes.list();
        <em>const</em> node = nodes.find((<em>node</em>) <em>=></em> <em>node</em>.resourceType === 'DATABASE');
        <em>const</em> database = await node?.asDatabase();
        <em>const</em> updatedRecord = await database?.records.update({
            id: <em>recordId</em>,
            cells: {
                Name: 'Updated Record',
            },
        });

        console.log('Database:', database);
        console.log('Record Updated:', updatedRecord);
    } catch (error) {
        console.error('Error updating record:', error);
    }
}

updateRecord('__REPLACE_WITH_RECORD_ID__');

Example 4: Delete a Record

Use this example to delete a specific record.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async <em>function</em> deleteRecord(<em>recordId</em>: <em>string</em>) {
    try {
        <em>const</em> spaces = await bika.space.list();
        <em>const</em> space = spaces[0];
        <em>const</em> nodes = await space.nodes.list();
        <em>const</em> node = nodes.find((<em>node</em>) <em>=></em> <em>node</em>.resourceType === 'DATABASE');
        <em>const</em> database = await node?.asDatabase();
        await database?.records.delete(<em>recordId</em>);

        console.log('Database:', database);
        console.log('Record Deleted:', <em>recordId</em>);
    } catch (error) {
        console.error('Error deleting record:', error);
    }
}

deleteRecord('__REPLACE_WITH_RECORD_ID__');

Example 5: List Automation Triggers

This example shows how to list automation triggers.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async function listTriggers() {
    try {
        const spaces = await bika.space.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        <em>const</em> node = nodes.find((<em>node</em>) <em>=></em> <em>node</em>.resourceType === 'AUTOMATION');
        const automation = await node?.asAutomation();
        const triggers = await automation?.triggers.list();
        
        console.log('Triggers:', triggers);
    } catch (error) {
        console.error('Error listing triggers:', error);
    }
}
listTriggers();

Example 6: Register an Outgoing Webhook

This example demonstrates how to register an outgoing webhook.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async function registerWebhook() {
    try {
        const spaces = await bika.space.list();
        const space = spaces[0];
        const outgoingWebhook = await space.outgoingWebhooks.register({
            eventType: 'ON_RECORD_CREATED',
            name: 'Create webhook',
            description: 'Exampple trigger when a new record cretaed',
            callbackURL: 'https://your-custom-callback-url.com',
        });

        console.log('Webhook Registered:', outgoingWebhook);
    } catch (error) {
        console.error('Error registering webhook:', error);
    }
}
registerWebhook();

Example 7: Embeded Bika.ai's UI(Coming soon)

Here are examples of embedding Bika.ai's UI into your own application.

If you want to incorporate Bika.ai's robust UI for databases, documents, and more, you can utilize the embed link API.

Generate an embed link to obtain a URL, and then use an <iframe> in your application.

import { Bika } from 'bika.ai';

const bika = new Bika({
    token: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
    baseURL: 'https://bika.ai/api/openapi/bika',
});

async <em>function</em> createEmbedLink(<em>resourceId</em>: <em>string</em>) {
    try {
        <em>const</em> spaces = await bika.space.list();
        <em>const</em> space = spaces[0];
        <em>const</em> embedLink = await space.embedLinks.create({
            objectType: 'NODE_RESOURCE',
            objectId: <em>resourceId</em>,
          });

        console.log('Embed Link:', embedLink);
    } catch (error) {
        console.error('Error creating embed link:', error);
    }
}
createEmbedLink('__NODE_RESOURCE_ID_YOU_WANT_TO_EMBED__');

// else
const embedLinks = await space.embedLink.list();
const deleteEmbedLink = await space.embedLink.delete({id: [embedLink.id](http://embedlink.id/)});

After creating an embedded Bika.ai UI, you can use the <iframe> tag to display it on your web page. Here's a simple example of how to do this:

<iframe src="YOUR_EMBEDDED_UI_URL" width="800" height="600"></iframe>

Replace YOUR_EMBEDDED_UI_URL with the actual URL of the embedded Bika.ai UI you created. You can adjust the width and height attributes according to your layout needs.

Conclusion

This Quick Start Guide provides basic examples to help you interact with the Bika.ai OpenAPI and SDK effectively. You can modify and expand these examples as needed for your specific use cases. For more detailed information, refer to the Bika.ai API Documentation.

Happy coding!

bika cta

推薦閱讀

推薦AI自動化模板

釘釘群消息定時提醒
通過 Bika 自動化定時發送消息至釘釘群組。您可以簡化定期通知、更新和警報的發送流程,提高團隊協作效率
Dynamic Email Automation for Partner Onboarding
Dynamic Email Automation for Partner Onboarding simplifies the onboarding process by automating personalized emails and follow-ups. It ensures timely communication, tracks partner engagement, and reduces manual work. With automated reminders and seamless integration, your team can focus on building stronger partnerships while the system handles the rest.
跨境電商供應商訂單協作
專為跨境電商設計的高效訂單協作流程,通過智能匹配和輪詢機制自動分配C2B訂單任務給合適供應商,實現從訂單接收到生產交付的全流程自動化管理,提升團隊效率並減少手動錯誤。
Eisenhower Matrix
Dwight D. Eisenhower, the 34th U.S. president and WWII's Allied Supreme Commander, also led NATO's forces. He developed the Eisenhower matrix to enhance his time management skills, making critical decisions in various roles.
Email 定時提醒
Email定時提醒是一項實用的功能,您可以設置提醒時間,在指定的日期和時間確保相關成員收到提醒郵件,以便及時處理相關事務,確保不會錯過重要信息。
Employee Engagement Survey
The Employee Engagement Survey template is designed to help organizations efficiently measure employee engagement and satisfaction.This tool helps identify differences in employee experiences and supports data-driven decisions for goal setting and workplace improvement.