# bubbleio-sdk

> TypeScript SDK for the bubble.io Data API

Latest version **0.0.31** (published 2023-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install bubbleio-sdk
pnpm add bubbleio-sdk
yarn add bubbleio-sdk
bun add bubbleio-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.31 |
| Published | 2023-05-30 |
| First published | 2021-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 40.6 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | Cameron Perry |
| Maintainers | cam-perry |

## Links

- npm: https://www.npmjs.com/package/bubbleio-sdk
- npm.io page: https://npm.io/package/bubbleio-sdk

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Recent versions

- 0.0.31 (latest) — 2023-05-30
- 0.0.30 — 2023-05-23
- 0.0.29 — 2022-10-23
- 0.0.28 — 2022-10-23
- 0.0.27 — 2022-10-23
- 0.0.26 — 2022-10-23
- 0.0.25 — 2022-08-04
- 0.0.24 — 2022-08-04
- 0.0.23 — 2022-08-04
- 0.0.22 — 2022-08-04
- 0.0.21 — 2022-08-04
- 0.0.20 — 2022-08-04
- 0.0.19 — 2022-08-04
- 0.0.18 — 2021-08-01
- 0.0.17 — 2021-08-01
- … 16 more at https://npm.io/package/bubbleio-sdk/versions

## README

# bubble-sdk

A TypeScript wrapper around the [Bubble Data API](https://manual.bubble.io/core-resources/api/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"](https://manual.bubble.io/help-guides/the-bubble-api/defining-the-api).

```ts
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.

```ts
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:

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

To search:

```ts
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:

```ts
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_

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

### Create and update

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

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

Update an object by calling `.save()`

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

---
_Source: https://npm.io/package/bubbleio-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
