Getting Started

You can install the package using your favorite package manager.

npm install @firmhouse/firmhouse-sdk
# or
yarn add @firmhouse/firmhouse-sdk

To get started, you need to create a new instance of the FirmhouseClient and provide it with an API token.

import { FirmhouseClient } from '@firmhouse/firmhouse-sdk';

const client = new FirmhouseClient({
  apiToken: "<your-api-token>"
});

You can use both Storefront and Write access tokens to interact with the Firmhouse API. Depending on the access type, you can perform different operations. If you try to perform an operation that is not allowed by the access type, you will receive an error.

Storefront Access

This access type is used for Storefront operations such as fetching products, creating carts, adding products to carts etc.

import { FirmhouseClient, Access } from '@firmhouse/firmhouse-sdk';

const client = new FirmhouseClient({
 apiToken: "<storefront-access-token>",
});

const { results } = await client.products.fetchAll();
const cart = await client.carts.create();
const { orderedProduct, subscription } = await client.carts.addProduct(cart.token, { productId: results[0].id, quantity: 1 });

Available Resources

Write Access

This access type has access to all resources and operations available in the Firmhouse API.

import { FirmhouseClient, Access, InvoiceStatusEnum } from '@firmhouse/firmhouse-sdk';

const client = new FirmhouseClient({
 apiToken: "<write-access-token>",
 accessType: Access.write
});

const subscription = await client.subscriptions.get("subscription-token");
const invoices = await client.invoices.fetchAll({ statuses: [InvoiceStatusEnum.Pending, InvoiceStatusEnum.Paid], subscriptionId: subscription.id }, {
 invoiceLineItems: true,
 payment: true
});

You should make sure that your write access token is kept secure and not exposed to the public.

Available Resources

All resources available with Storefront access are also available with Write access.

Last updated