Getting Started
You can install the package using your favorite package manager.
npm install @firmhouse/firmhouse-sdk
# or
yarn add @firmhouse/firmhouse-sdkTo 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 } 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
client.carts: CartsResourceclient.products: ProductsResourceclient.plans: PlansResourceclient.selfServiceCenterToken: SelfServiceCenterTokenResource
Write Access
This access type has access to all resources and operations available in the Firmhouse API.
You should make sure that your write access token is kept secure and not exposed to the public.
Available Resources
writeAccessClient.subscriptions: SubscriptionsResourcewriteAccessClient.invoices: InvoicesResourcewriteAccessClient.projects: ProjectsResource
All resources available with Storefront access are also available with Write access.
Common Actions
The following examples assume that you have created client with a Storefront access token and writeAccessClient with a Write access token as shown above.
Fetch Products and Plans
Create a Cart and Add a Product
Apply a Discount Code and Calculate Cart Totals
calculateCartTotals uses the largest active promotion when multiple promotions are present; promotions do not stack. Discounts are capped at the subtotal, and shipping is not included.
Fetch Project Details and Invoices
Retrieve a Subscription Through Self-Service Login
First, send the subscriber a Self Service Center login link:
When the subscriber follows the link, exchange its login token for the subscription:
Use Subscription and Extra-Field Helpers
Last updated
Was this helpful?