Guide
Basic
Automation Guide
Database
Integration Guide
Self-hosted
Open API
Business AI Agent Template
Cookbook
Reference
Automation Triggers
Automation Actions
Integrations
Node Resources
Database Views
Database Fields
Dashboard Widgets
Missions
Ai Wizard
Formula
Space
Release Notes
Videos

OpenAPI Quick Start

Welcome to the Bika.ai 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.

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

Example 1: Fetch Data

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

javascript

复制

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

async function fetchData() {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        const node = nodes[0];
        const database = await node.asDatabase();
        const records = await database.records.list();
        console.log('Records:', records);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}
fetchData();

Example 2: Create a New Record

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

javascript

复制

async function createRecord() {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        const node = nodes[0];
        const database = await node.asDatabase();
        const newRecord = await database.records.create({
            fields: {
                Name: '新记录',
                Description: '这是一个新创建的记录',
            },
        });

        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.

javascript

复制

async function updateRecord(recordId) {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        const node = nodes[0];
        const database = await node.asDatabase();
        const updatedRecord = await database.records.update(recordId, {
            fields: {
                Description: '更新后的描述',
            },
        });

        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.

javascript

复制

async function deleteRecord(recordId) {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        const node = nodes[0];
        const database = await node.asDatabase();
        await database.records.delete(recordId);
        console.log('Record Deleted:', recordId);
    } 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.

javascript

复制

async function listTriggers() {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const nodes = await space.nodes.list();
        const node = nodes[0];
        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.

javascript

复制

async function registerWebhook() {
    try {
        const spaces = await bika.spaces.list();
        const space = spaces[0];
        const outgoingWebhook = await space.outgoingWebhooks.create({
            eventType: 'ON_RECORD_CREATED',
            name: '记录创建Webhook',
            description: '当记录被创建时触发',
            callbackURL: 'https://your-custom-callback-url.com',
        });

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

Conclusion

This Quick Start Guide provides basic examples to help you interact with the Bika.ai API 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!

Quick Start

Let's quick start with curl example:

curl -X GET "https://bika.ai/api/openapi/bika/v1/system/meta" -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"
# Response: {"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"}}}%

Bika.ai's offical JavaScript use beautiful Object-Oriented Programming (OOP) style for your better use.

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

Examples to use Bika.ai offical Node.js SDK. (TypeScript example)

Get Spaces:

import { Bika } from 'bika.ai';

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

// firstly, fetch your spaces
const spaces = await bika.spaces.list();
// now we use your first space as our operations
const space = spaces[0];

Find Node Resources (Database, Automation, Folder, Documents, etc.):

// find node resources
const nodes = await space.nodes.list();
// get one node resource
const node = nodes[0];
const database = await node.asDatabase();
const automation = await node.asAutomation();

Here’s an example of Create, Read, Update, and Delete (CRUD) operations for databases.

Given that Bika.ai's database can handle billions of rows, you can use Bika.ai databases as a fully functional production database, such as for an order table, user table, and more.

// notice,  use `asXXX`,depends on your node resource type, includes database, automation, folder, and so-on
const database = await node.asDatabase();
const records = await database.records.list();
const views = await database.views.list();

CRUD Automations:

const automation = await node.asAutomation();
const triggers = await automation.triggers.list();
const actions = await automation.actions.list();

Here are examples of registering global-scope or space-scope outgoing webhooks (Server Events in Bika.ai).

You can utilize outgoing webhooks to send HTTP POST requests to your callback URL whenever a specific event takes place in Bika.ai.

Use cases include contact synchronization, data synchronization, custom notifications, plugins, and more.

// Outoging Webhooks
// Register a Bika.ai server event, and send a HTTP POST request to your callback URL
const outgoingWebhook = await space.outgoingWebhooks.create({
  eventType: 'ON_RECORD_CREATED',
  name: 'Test Outgoing Webhook',
  description: 'Test Outgoing Webhook Desc',
  callbackURL: 'https://your-custom-callback-url.com',
});
const outgoingWebhooks = await space.outgoingWebhooks.list();
const delteOutgoingWebhook = await space.outgoingWebhooks.delete({id: outgoingWebhook.id});

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.

// Embed Links
// You can embed Bika.ai's UI into your own application
const embedLink = await space.embedLink.create({
  objectType: 'NODE_RESOURCE',
  objectId: '__NODE_RESOURCE_ID_YOU_WANT_TO_EMBED__',
});
const embedLinks = await space.embedLink.list();
const deleteEmbedLink = await space.embedLink.delete({id: embedLink.id});
// ...

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

bika cta

Recommend Reading

Recommend AI Automation Templates

Sales Strategy
This template helps sales teams set goals, track the progress of strategic plans, and ensure business growth is achieved
Scrum Sprint Task Management Automation
Streamline your Scrum sprint management with this powerful template. Effortlessly organize tasks, track progress, manage bugs, and automate notifications for sprint completion and task updates. Leverage auto-generated tasks from issues or bugs and set up task review reminders to keep your team aligned and ensure timely delivery of sprint goals.
Send Emails in Bulk
Super easy-to-use bulk email sending function, an intuitive data table, enter email addresses or collect them through forms, trigger to send in bulk, and see open rates and reply rates
Send Emails in Bulk (Tag Triggered)
Super simple and easy-to-use bulk email sending feature. An intuitive data table to input email addresses or collect them through forms, trigger bulk sending based on tag changes, and view open rates and reply rates.
Simple Applicant Tracker
An adaptable applicant tracking system suitable for small to medium HR teams. Manage recruitment processes, candidate information, set up internal hiring programs effortlessly, and easily track candidate statuses.
A Simple & Powerful CRM
A Simple & Powerful CRM offers essential resources for managing customer relationships effectively. Whether you're starting out or optimizing existing processes, this CRM toolkit provides valuable insights and support to enhance your business operations.