SDK · Node.js

Build on Bequest, in Node.js.

Idiomatic client for the Bequest API. Same endpoints as REST, same idempotency, native error types.

Install

npm install bequest

Runtime

Node 18+

Auth

Bearer token via BQ_KEY env var.

1. Initialize

Authenticate once.

import Bequest from 'bequest';

const bq = new Bequest(process.env.BQ_KEY);
2. Send a gift

One call. One dollar.

const gift = await bq.gifts.create({
  from: 'usr_8f3...',
  to:   'org_a91...',
  amount_cents: 2500,
  memo: 'Spring drive'
}, { idempotencyKey: req.id });

console.log(gift.status); // 'settling'
3. Open a campaign

Hosted page in one POST.

const campaign = await bq.campaigns.create({
  name: 'Spring Build-a-Well Drive',
  goal_cents: 7500000,
  story: 'We are building 12 wells in...',
  status: 'live'
});
console.log(campaign.url); // hosted page URL
4. Open a pool

Standing commitments, batched annually.

const pool = await bq.pools.create({
  name: 'Cedar Block Mutual Aid',
  flavor: 'community',
  legal_structure: 'mutual_aid',
  distribution_mechanism: 'threshold'
});

await bq.pools.disburse(pool.id, {
  to: 'usr_77...', amount_cents: 35000
});
5. Listen for webhooks

Signed payloads, replay-safe.

import express from 'express';
const app = express();

app.post('/webhooks/bequest',
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const event = bq.webhooks.constructEvent(
      req.body,
      req.headers['bq-signature'],
      process.env.BQ_WEBHOOK_SECRET
    );
    if (event.type === 'gift.settled') {
      ledger.write(event.data);
    }
    res.json({ received: true });
  });
6. Handle errors

Typed by category.

try {
  await bq.gifts.create({ ... });
} catch (e) {
  if (e instanceof Bequest.IdempotencyError) {
    // Reuse existing gift
  } else if (e instanceof Bequest.RateLimitError) {
    // Backoff and retry
  } else if (e instanceof Bequest.AuthError) {
    // Rotate key
  } else {
    throw e;
  }
}
Reference

Full API docs.

The complete reference covers every resource, every parameter, every status code.

Open the API reference