# Getting Started

You can install the package using your favorite package manager.

```bash
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.

```typescript
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.

```typescript
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

* `client.carts`: [CartsResource](/sdks/firmhouse-sdk/reference/resources/carts.md)
* `client.products`: [ProductsResource](/sdks/firmhouse-sdk/reference/resources/products.md)
* `client.plans`: [PlansResource](/sdks/firmhouse-sdk/reference/resources/plans.md)
* `client.selfServiceCenterToken`: [SelfServiceCenterTokenResource](https://github.com/firmhouse/developer-docs/blob/main/docs/sdks/firmhouse-sdk/reference/resources/self-service-token.md)

## Write Access

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

```typescript
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
});
```

{% hint style="danger" %}
You should make sure that your write access token is kept secure and not exposed to the public.
{% endhint %}

## Available Resources

* `client.subscriptions`: [SubscriptionsResource](/sdks/firmhouse-sdk/reference/resources/subscriptions.md)
* `client.invoices`: [InvoicesResource](/sdks/firmhouse-sdk/reference/resources/invoices.md)
* `client.projects`: [ProjectsResource](/sdks/firmhouse-sdk/reference/resources/projects.md)

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.firmhouse.com/sdks/firmhouse-sdk/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
