> ## Documentation Index
> Fetch the complete documentation index at: https://docs.layerfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Authenticate, onboard a business, and surface accounting in your product.

This guide walks you through the core path to offering accounting in your product with Layer: authenticate, onboard a business, pass in financial data, and surface it back to your users. For the concepts behind these steps, see [Key concepts](/guides/key-concepts).

## Prerequisites

Before getting started with Layer's API, you will need:

* A Layer account. Reach out to your Layer contact or [contact our team](https://www.layerfi.com/contact).
* Client credentials (`client_id` and `client_secret`) provided by Layer.

## Environments

Layer provides two environments for development and production use:

| Environment    | Base URL                      | OAuth Scope                           |
| -------------- | ----------------------------- | ------------------------------------- |
| **Sandbox**    | `https://sandbox.layerfi.com` | `https://sandbox.layerfi.com/sandbox` |
| **Production** | `https://api.layerfi.com`     | `https://api.layerfi.com/production`  |

Use sandbox for development and testing. All examples in this guide use the sandbox environment.

<Steps>
  <Step title="Get a bearer token">
    Layer uses OAuth2's client credentials flow to authenticate API clients. Calls to the Layer API require a bearer access token. To receive one, provide your `client_id` and `client_secret` in the body of a POST request to Layer's authorization server.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X POST https://auth.layerfi.com/oauth2/token  \
        -u <client_id>:<client_secret>  \
        -H "Content-Type: application/x-www-form-urlencoded" \
        --data-urlencode "grant_type=client_credentials" \
        --data-urlencode "scope=https://sandbox.layerfi.com/sandbox" \
        --data-urlencode "client_id=<client_id>"
      ```

      ```python Python theme={null}
      import requests
      from requests.auth import HTTPBasicAuth

      response = requests.post(
          "https://auth.layerfi.com/oauth2/token",
          auth=HTTPBasicAuth("<client_id>", "<client_secret>"),
          headers={"Content-Type": "application/x-www-form-urlencoded"},
          data={
              "grant_type": "client_credentials",
              "scope": "https://sandbox.layerfi.com/sandbox",
              "client_id": "<client_id>"
          }
      )

      token_data = response.json()
      access_token = token_data["access_token"]
      ```

      ```javascript Node.js theme={null}
      const axios = require('axios');

      const getAccessToken = async () => {
        const response = await axios.post(
          'https://auth.layerfi.com/oauth2/token',
          new URLSearchParams({
            grant_type: 'client_credentials',
            scope: 'https://sandbox.layerfi.com/sandbox',
            client_id: '<client_id>'
          }),
          {
            auth: {
              username: '<client_id>',
              password: '<client_secret>'
            },
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }
        );

        return response.data.access_token;
      };
      ```
    </CodeGroup>

    The authorization server will respond with your granted access token:

    ```json theme={null}
    {
      "access_token": "<access_token>",
      "expires_in": 3600,
      "token_type": "Bearer"
    }
    ```

    Extract the `access_token` value from the response. You'll use this in the `Authorization` header for all API requests.
  </Step>

  <Step title="Make a test API call">
    Use the access token to make a request to the API by including it as a Bearer token in the authorization header.

    <CodeGroup>
      ```bash cURL theme={null}
      curl https://sandbox.layerfi.com/whoami \
        -H "Authorization: Bearer <access_token>" 
      ```

      ```python Python theme={null}
      import requests

      response = requests.get(
          "https://sandbox.layerfi.com/whoami",
          headers={"Authorization": f"Bearer {access_token}"}
      )

      print(response.json())
      ```

      ```javascript Node.js theme={null}
      const axios = require('axios');

      const response = await axios.get(
        'https://sandbox.layerfi.com/whoami',
        {
          headers: {
            'Authorization': `Bearer ${accessToken}`
          }
        }
      );

      console.log(response.data);
      ```
    </CodeGroup>

    The API will respond with your client name and client id:

    ```json theme={null}
    {
      "data":{
        "type":"whoami",
        "clientName":"Layer Example",
        "clientId":"018f1657-dc66-7482-917b-c0c0e532f52b"
      }
    }
    ```

    <Info>
      Access tokens expire after 1 hour. To refresh your access token, make another call to Layer's authorization endpoint with your `client_id` and `client_secret`. We recommend refreshing tokens for new sets of requests rather than persisting access tokens.
    </Info>
  </Step>

  <Step title="Onboard a business">
    Each of your SMB customers is represented in Layer as a `Business`. Creating one also provisions its `General Ledger`, where all accounting data is stored.

    See [Onboarding a Business](/guides/business-onboarding) for the full flow, then [create a business](/api-reference/v1/create-business) via the API.
  </Step>

  <Step title="Connect or import financial data">
    Pass your customers' financial activity to Layer so it can be categorized, reconciled, and reported on.

    * [Connect bank accounts and import transactions](/guides/importing-bank-data)
    * [Import invoices and revenue data](/guides/importing-sales-ar-data)
  </Step>

  <Step title="Surface accounting in your product">
    Choose how to display accounting features. Either method can deliver any capability, and you can mix them.

    * **Embedded Components**: drop in Layer's pre-built React UI. See [Embedding UI components](/guides/embedded-components).
    * **API**: build your own UX directly on the [Layer API](/api-reference/business/business).
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Key concepts" icon="lightbulb" href="/guides/key-concepts">
    Understand platforms, businesses, and the general ledger.
  </Card>

  <Card title="Embedding UI components" icon="puzzle-piece" href="/guides/embedded-components">
    Add Layer's pre-built components to your frontend.
  </Card>

  <Card title="Onboard a business" icon="user-plus" href="/guides/business-onboarding">
    Create your first business and connect its data.
  </Card>

  <Card title="MCP server" icon="sparkles" href="/insights/mcp-server">
    Give AI agents access to Layer via Model Context Protocol.
  </Card>
</CardGroup>
