node-bubbleio
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

node-bubbleio

NPM

Bubble.io Data and Workflow API client for node.js

Installation & Setup

Install

npm i node-bubbleio --save

Configuration

Configure your application by passing these values into BubbleIO.init:

  • apiToken: Your API token
  • domain: Full domain to your API (include .bubbleapps.io if not using a custom domain)
  • isLive: Whether to use the live version of your API
BubbleIO.init({
  domain: 'my-amazing-app.bubbleapps.io',
  apiToken: 'a6se92a9dd6cb69979128a6969c98c89'
});

Or you can set these via environment variables and just run BubbleIO.init:

//.env
BUBBLE_DOMAIN=my-amazing-app.bubbleapps.io
BUBBLE_API_TOKEN=a6se92a9dd6cb69979128a6969c98c89
BUBBLE_LIVE=false
BubbleIO.init()

Data API

Define your Things

Each Data API endpoint needs to be defined as its own class:

const BubbleIO = require('node-bubbleio');

class Thing extends BubbleIO.DataAPI {
  _type = 'thing'; // This is the object name
}

In Typescript, you also pass in the custom attributes of your thing

class Thing extends BubbleIO.DataAPI {
  _type = 'thing';

  title_text: string;
}

Retrieve a thing by ID

If you already know the ID of a thing, you can get the thing from the server using the static get method:

const thing = await Thing.get('1449154312665x293260311940684900');

Modify a thing

After creating or getting a thing, you can edit the thing directly and then save your changes using the save method:

thing.title_text = 'My new thing';
await thing.save()

The original thing in your code will be updated with the latest version from the API. For example, the Modified Date will be up to date.

Delete a thing

To delete a thing use delete method:

await thing.delete()

Create a new thing

To create a thing, you can use the static create method:

const newThing = await Thing.create({
  title_text: 'My new thing'
});

Or you can create a new thing and use the save method:

const newThing = new Thing({
  title_text: 'My new thing'
})
await newThing.save();

newThing will have all the updated fields from the Data API like _id and Created Date.

Bulk create things

If you need to create many new things in a single operation, you can do that using the bulkCreate method:

const newThings = await Thing.bulkCreate([{
  title_text: 'Thing 1'
}, {
  title_text: 'Thing 2'
}]);
console.log(newThings[0].title_text) // Thing 1

This will return an array of things.

Getting a list of things and search

To retrieve a list of things, optionally using search constraints, use the find method:

const found = await Thing.find({
  constraints: [
    {
      key: 'title_text',
      constraint_type: 'text contains',
      value: 'Test',
    },
  ],
  limit: 1,
  cursor: 2,
  sort_field: 'Created Date',
  descending: true
});

This method supports all pagination, search constraints, and sorting options.

Workflow API

Define your Workflow

Each Workflow API endpoint needs to be defined using the BubbleIO.WorkflowAPI class:

const BubbleIO = require('node-bubbleio');

class MyAPI = new BubbleIO.WorkflowAPI({
  name: 'myworkflow'
})

Triggering a Workflow

A Workflow API call can send a JSON body and querystring parameters.

// Using just JSON in the body
await MyAPI.send({
  value: 23
});

// Sending a `param` querystring as well
await MyAPI.send({
  value: 23
}, {
  param: true
});

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i node-bubbleio

Weekly Downloads

2

Version

0.0.6

License

MIT

Unpacked Size

127 kB

Total Files

21

Last publish

Collaborators

  • ccummings