npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bunnyapp/api-client

v3.1.0

Published

Node.js client for Bunny CRM

Readme

bunny-node

A node sdk for Bunny CRM

Setup

Install the latest package.

npm install @bunnyapp/api-client --save

Create a Bunny api client using either a valid access token or client credentials.

Access Token

The benefit of providing an accessToken is the request will be faster as an access token does not need to be generated. The downside of this approach is that if the token expires then your requests will start to fail.

TypeScript:

import Bunny from "@bunnyapp/api-client";

const bunny = new Bunny({
  baseUrl: "https://<subdomain>.bunny.com",
  accessToken: "<bunny-access-token>",
});

JavaScript:

const BunnyClient = require("@bunnyapp/api-client");

const bunny = new BunnyClient({
  baseUrl: "https://<subdomain>.bunny.com",
  accessToken: "<bunny-access-token>",
});

Client Credentials

Alternately you can provide clientId, clientSecret, & scope. In this case the client will generate an access token and if the token expires it will generate another one.

TypeScript:

import Bunny from "@bunnyapp/api-client";

const bunny = new Bunny({
  baseUrl: "https://<subdomain>.bunny.com",
  clientId: "<bunny-client-id>",
  clientSecret: "<bunny-client-secret>",
  scope: "standard:read standard:write",
});

JavaScript:

const BunnyClient = require("@bunnyapp/api-client");

const bunny = new BunnyClient({
  baseUrl: "https://<subdomain>.bunny.com",
  clientId: "<bunny-client-id>",
  clientSecret: "<bunny-client-secret>",
  scope: "standard:read standard:write",
});

Helper methods

This SDK provides helper methods for common Bunny API operations. The response types match the GraphQL schema.

TypeScript:

import {
  SubscriptionOptions,
  Subscription,
  Mutation,
  Tenants,
} from "@bunnyapp/api-client";

// Create a new subscription
const subscription: Subscription = await bunny.subscriptionCreate(
  "priceListCode",
  {
    // Subscription settings
    trial: false, // Optional: Start with a trial period
    evergreen: true, // Optional: Auto-renew subscription

    // Account identification (Must use either accountId OR account details)
    accountId: "existing-123", // Required unless using accountName: Use existing account

    // Account details (used if accountId is not provided)
    accountName: "Acme Corp", // Required unless using accountId: Company/Account name
    ownerUserId: "user-123",
    phone: "555-0123",
    fax: "555-0124",
    website: "www.acme.com",

    // Optional: Billing address
    billingStreet: "123 Main St",
    billingCity: "San Francisco",
    billingZip: "94105",
    billingState: "CA",
    billingCountry: "US",

    // Billing contact information
    firstName: "John", // Required
    lastName: "Doe",
    email: "[email protected]", // Required
    mobile: "555-0125",
    salutation: "Mr",
    title: "CEO",

    // Optional: Billing contact mailing address
    mailingStreet: "456 Market St",
    mailingCity: "San Francisco",
    mailingZip: "94105",
    mailingState: "CA",
    mailingCountry: "US",

    // Optional: Tenant information
    tenantCode: "tenant-123",
    tenantName: "Acme Team",
  }
);

// Get a session token for the Bunny customer portal
const portalSession = await bunny.portalSessionCreate("tenantCode");

// Optionally supply a return url to get back to your app
const portalSessionWithUrl = await bunny.portalSessionCreate(
  "tenantCode",
  "https://example.com"
);

// Default session length is 24 hours but you can change it. e.g 12 hours
const portalSessionWithDuration = await bunny.portalSessionCreate(
  "tenantCode",
  "https://example.com",
  12
);

// Track usage for billing
const usageTracking = await bunny.featureUsageCreate(
  "featureCode",
  1,
  "subscriptionId",
  new Date()
);

// Update account details including billing address for account
const updatedAccount = await bunny.accountUpdateByTenantCode("tenantCode", {
  billingStreet: "123 Main Street",
  billingCity: "Pleasantville",
  billingState: "CA",
  billingZip: "90210",
  billingCountry: "US",
});

JavaScript:

// Create a new subscription
const subscription = await bunny.subscriptionCreate("priceListCode", {
  // Subscription settings
  trial: false, // Optional: Start with a trial period
  evergreen: true, // Optional: Auto-renew subscription

  // Account identification (Must use either accountId OR account details)
  accountId: "existing-123", // Required unless using accountName: Use existing account

  // Account details (used if accountId is not provided)
  accountName: "Acme Corp", // Required unless using accountId: Company/Account name
  ownerUserId: "user-123",
  phone: "555-0123",
  fax: "555-0124",
  website: "www.acme.com",

  // Optional: Billing address
  billingStreet: "123 Main St",
  billingCity: "San Francisco",
  billingZip: "94105",
  billingState: "CA",
  billingCountry: "US",

  // Billing contact information
  firstName: "John", // Required
  lastName: "Doe",
  email: "[email protected]", // Required
  mobile: "555-0125",
  salutation: "Mr",
  title: "CEO",

  // Optional: Billing contact mailing address
  mailingStreet: "456 Market St",
  mailingCity: "San Francisco",
  mailingZip: "94105",
  mailingState: "CA",
  mailingCountry: "US",

  // Optional: Tenant information
  tenantCode: "tenant-123",
  tenantName: "Acme Team",
});

// Get a session token for the Bunny customer portal
const portalSession = await bunny.portalSessionCreate("tenantCode");

// Optionally supply a return url to get back to your app
const portalSessionWithUrl = await bunny.portalSessionCreate(
  "tenantCode",
  "https://example.com"
);

// Default session length is 24 hours but you can change it. e.g 12 hours
const portalSessionWithDuration = await bunny.portalSessionCreate(
  "tenantCode",
  "https://example.com",
  12
);

// Track usage for billing
const usageTracking = await bunny.featureUsageCreate(
  "featureCode",
  1,
  "subscriptionId",
  new Date()
);

// Update account details including billing address for account
const updatedAccount = await bunny.accountUpdateByTenantCode("tenantCode", {
  billingStreet: "123 Main Street",
  billingCity: "Pleasantville",
  billingState: "CA",
  billingZip: "90210",
  billingCountry: "US",
});

Error handling

If there is an error with a helper method an exception will be raised.

TypeScript:

import { Subscription } from "@bunnyapp/api-client";

try {
  const subscription: Subscription = await bunny.subscriptionCreate(
    "priceListCode",
    {
      trial: true,
      evergreen: true,
      accountName: "Test Account",
    }
  );
  // Handle successful subscription
} catch (error) {
  if (error instanceof Error) {
    console.error(error.message);
  }
}

// Or using promises
bunny
  .subscriptionCreate("priceListCode", {
    trial: true,
    evergreen: true,
    accountName: "Test Account",
  })
  .then((subscription: Subscription) => {
    // Handle successful subscription
  })
  .catch((error: Error) => {
    console.error(error.message);
  });

JavaScript:

try {
  const subscription = await bunny.subscriptionCreate("priceListCode", {
    trial: true,
    evergreen: true,
    accountName: "Test Account",
  });
  // Handle successful subscription
} catch (error) {
  console.error(error.message);
}

// Or using promises
bunny
  .subscriptionCreate("priceListCode", {
    trial: true,
    evergreen: true,
    accountName: "Test Account",
  })
  .then((subscription) => {
    // Handle successful subscription
  })
  .catch((error) => {
    console.error(error.message);
  });

Direct GraphQL queries

If the helper methods don't cover your needs, you can make direct GraphQL queries. The SDK provides full TypeScript support for the GraphQL schema.

TypeScript:

import { Tenants } from "@bunnyapp/api-client";

// Example using generated GraphQL types
const query = `query tenants ($filter: String, $limit: Int) {
    tenants (filter: $filter, limit: $limit) {
        platform {
            id
            name
            code
        }
        id
        name
        code
    }
}`;

const variables = {
  filter: "",
  limit: 10,
};

// Use the generated Tenants type instead of custom TenantsResponse interface
const response = await bunny.query<{ data: { tenants: Tenants[] } }>(
  query,
  variables
);

JavaScript:

const query = `query tenants ($filter: String, $limit: Int) {
    tenants (filter: $filter, limit: $limit) {
        platform {
            id
            name
            code
        }
        id
        name
        code
    }
}`;

const variables = {
  filter: "",
  limit: 10,
};

const response = await bunny.query(query, variables);

Validate a webhook payload

When Bunny sends a webhook request it includes a x-bunny-signature header which can be used to validate the authenticity of the payload body.

Bunny will provide a signing token which you will need to store in your application and use for validating the webhook.

TypeScript:

interface WebhookRequest {
  headers: {
    "x-bunny-signature": string;
  };
  body: unknown;
}

const signature: string = req.headers["x-bunny-signature"];
const payload: unknown = req.body;
const signingToken: string = "<secret signing token>";

const valid: boolean = bunny.webhooks.validate(
  signature,
  payload,
  signingToken
);

JavaScript:

const signature = req.headers["x-bunny-signature"];
const payload = req.body;
const signingToken = "<secret signing token>";

const valid = bunny.webhooks.validate(signature, payload, signingToken);

Test

Run unit tests

npm test