Skip to content

cultureally/bubbleio-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bubble-sdk

A TypeScript wrapper around the Bubble Data API.

Usage

First, you will need to provide your app and apiKey from Bubble.

Make sure to follow Bubble's documentation for "Activating the API" and "Setting up the GET/DATA API".

import BubbleSDK from "bubble-sdk";

BubbleSDK.init({
  app: "your-app-name",
  apiKey: "your-bubble-api-key",
});

Define your types

Then you can create a class for each Data type in Bubble. You must define the type. This type is the name of the type as it appears in the URL when making requests to Bubble.

class User extends BubbleSDK.DataType {
  // The name of the type in Bubble.
  type = "user";

  // Define your custom fields with their types.
  email: string;
  first_name: string;
}

Fetching data

To fetch by ID:

const user: User = await User.getByID("123");

To search:

const res: SearchResponse<User> = await User.search({
  constraints: [
    { key: "first_name", constraint_type: "contains", values: ["asdf"] },
  ],
  sort: {
    sort_field: "Created Date",
    descending: true,
  },
});

To get one item by searching:

const user: User | null = await User.getFirst(/** Accepts search options */);

To get all data matching search: Use with caution as this will make unlimited API requests to Bubble in order to page through all results

const users: User[] = await User.getAll(/** Accepts search options */);

Create and update

Creating a new object returns the ID of the created object.

const userID: string = await User.create({ email: "..." });

Update an object by calling .save()

const user: User = await User.getByID("123");
user.email = "new@email.com";
await user.save();

About

SDK for the Bubble Data API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published