Base44 Sdk

Base44 Sdk automation and integration for flexible and scalable app development

Base44 SDK is a client library for integrating Base44 platform services into applications through programmatic APIs. It covers authentication, data operations, real-time subscriptions, file storage, and serverless function invocation that enable developers to build applications leveraging Base44 backend services from any JavaScript or TypeScript environment.

What Is This?

Overview

Base44 SDK provides structured approaches to consuming Base44 platform services programmatically. It handles authenticating users through the platform identity service, performing CRUD operations on platform-managed data collections, subscribing to real-time data changes through WebSocket connections, uploading and retrieving files from platform storage, invoking serverless functions deployed on Base44 infrastructure, and managing user sessions and permissions through the SDK interface.

Who Should Use This

This skill serves frontend developers building applications that consume Base44 backend services, mobile developers integrating Base44 data into cross-platform apps, backend engineers extending Base44 with custom server-side logic, and teams building internal tools on the Base44 platform.

Why Use It?

Problems It Solves

Calling platform APIs directly through HTTP requests requires managing authentication tokens, request formatting, and error handling manually. Without an SDK, real-time data subscriptions need custom WebSocket implementation and reconnection logic. Building data queries from raw API calls leads to verbose code that obscures business logic. Managing file uploads with progress tracking and retry logic adds complexity to storage operations.

Core Highlights

Typed data access provides autocomplete and compile-time validation for collection operations. Real-time subscriptions handle WebSocket connection management and automatic reconnection. Authentication wraps token lifecycle including refresh and session persistence. File operations simplify uploads with progress callbacks and chunked transfer.

How to Use It?

Basic Usage

import { Base44 } from "@base44/sdk";

const client = new Base44({
  projectId: "proj_abc123",
  apiKey: process.env.BASE44_API_KEY
});

// Authenticate a user
const session = await client.auth.signIn({
  email: "user@example.com",
  password: "securePassword"
});

// Create a record in a collection
const task = await client.collection("tasks").create({
  title: "Review pull request",
  status: "pending",
  assignee: session.user.id
});

// Query records with filters
const pending = await client.collection("tasks")
  .where("status", "==", "pending")
  .orderBy("createdAt", "desc")
  .limit(20)
  .get();

// Subscribe to real-time updates
client.collection("tasks")
  .where("assignee", "==", session.user.id)
  .onSnapshot((snapshot) => {
    snapshot.changes.forEach((change) => {
      console.log(change.type, change.doc.data());
    });
  });

Real-World Examples

import { Base44 } from "@base44/sdk";

class TaskService {
  constructor(client) {
    this.client = client;
    this.tasks = client.collection("tasks");
  }

  async createWithAttachment(taskData, file) {
    const uploadResult = await this.client.storage
      .upload(file, {
        folder: "task-attachments",
        onProgress: (pct) =>
          console.log(`Upload: ${pct}%`)
      });
    return this.tasks.create({
      ...taskData,
      attachment: uploadResult.url,
      attachmentName: file.name
    });
  }

  async assignToTeam(taskId, teamId) {
    const members = await this.client
      .collection("team_members")
      .where("teamId", "==", teamId)
      .get();
    const workloads = await Promise.all(
      members.docs.map(async (member) => {
        const count = await this.tasks
          .where("assignee", "==", member.id)
          .where("status", "==", "pending")
          .count();
        return { id: member.id, count };
      })
    );
    workloads.sort((a, b) => a.count - b.count);
    return this.tasks.update(taskId, {
      assignee: workloads[0].id,
      status: "assigned"
    });
  }

  watchAssigned(userId, callback) {
    return this.tasks
      .where("assignee", "==", userId)
      .where("status", "in", ["pending", "assigned"])
      .onSnapshot(callback);
  }
}

const client = new Base44({ projectId: "proj_abc" });
const service = new TaskService(client);
const task = await service.createWithAttachment(
  { title: "Deploy update", status: "pending" },
  selectedFile
);

Advanced Tips

Use collection references as singletons to benefit from internal caching and connection reuse. Batch write operations into transactions when updating related records to maintain data consistency. Unsubscribe from real-time listeners when components unmount to prevent memory leaks and unnecessary network traffic.

When to Use It?

Use Cases

Use Base44 SDK when building frontend applications that need authenticated data access to Base44 collections, when implementing real-time features like live dashboards or collaborative editing, when managing file uploads and downloads through the platform storage service, or when invoking serverless functions from client-side code.

Related Topics

Firebase SDK patterns, BaaS client libraries, real-time data synchronization, authentication token management, and serverless function invocation complement Base44 SDK usage.

Important Notes

Requirements

Node.js or browser environment supporting ES modules. Active Base44 project with configured collections. Valid API key or user credentials for authentication.

Usage Recommendations

Do: initialize the SDK client once and share it across your application modules. Use typed collection definitions when working in TypeScript for compile-time safety. Handle authentication state changes to redirect unauthenticated users appropriately.

Don't: expose API keys in client-side code for public-facing applications without configuring security rules. Create multiple SDK instances pointing to the same project, which wastes connections. Ignore subscription cleanup, which leads to memory leaks in long-running applications.

Limitations

Offline data persistence depends on platform support and is not available in all environments. Query capabilities are limited to the operators and indexes supported by the Base44 data layer. SDK version updates may require migration when platform API versions change.