> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mercoa.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mercoa.com/_mcp/server.

If you are using Mercoa for just payments check out our [Creating Payouts via API](/common-concepts/creating-payouts-via-api) guide.

Mercoa has a fully documented [REST API](/api-reference) that can be used in any language. We also have [Node](/sdks/javascript), [Python](/sdks/python), [Java](/sdks/java), and [Go](/sdks/go) SDKs for easy backend integration.

At Mercoa, we aim to provide a seamless and whitelabeled experience for your users.
As part of this experience, Mercoa does not force users to create a new account or log in to a different system.

Instead, Mercoa uses [JWT tokens](https://jwt.io/) that you can generate to transparently authenticate the user session on the frontend.

### Steps to generate a token

1. User logs into your platform
2. Find the Mercoa [Entity](/api-reference/entity/find) that corresponds to that user's business.
3. Optional: [Sync](/api-reference/entity/user/create) individual users and their roles. This is required for [Approvals](/accounts-payable/approval-policies).
4. Generate a JWT and pass it to the frontend.
5. Use the JWT with our [frontend SDK](/sdks/javascript), [React Components](/react-library/overview), or embedded iFrame.

## Creating a Token

Let's create an endpoint that authenticates the user, generates a JWT with the `entityId`, and return the generated token. We will use Mercoa's [Generate JWT Token](/api-reference/entity/get-token) endpoint to make this easy.

#### Python Django

```python
from django.http import HttpResponse
from mercoa.client import Mercoa

client = Mercoa(token="YOUR_API_KEY")

def generate_mercoa_token(request):
  client.entity.get_token(entity_id="ENTITY_ID_FROM_STEP_ONE",{})
  return HttpResponse(token)
```

#### Node Express

```javascript
import { MercoaClient } from "@mercoa/javascript"

const mercoa = new MercoaClient({
  token: "YOUR_API_KEY",
})

app.get('/generateMercoaToken', async (req, res) => {
  const token = await mercoa.entity.getToken("ENTITY_ID_FROM_STEP_ONE",{})
  res.send(token)
})
```

#### Next.js

```javascript
// Create an API route called /api/generateMercoaToken

import { MercoaClient } from '@mercoa/javascript'

const mercoa = new MercoaClient({
  token: "YOUR_API_KEY",
})

export default async function handler(req, res) {
  const token = await mercoa.entity.getToken("ENTITY_ID_FROM_STEP_ONE")
  res.send(token)
}
```

## Using the Token

Now that we have a token, we can use it to authenticate the user in our frontend application. Tokens have a default expiration of 1 hour, but you can change this by passing in the `expiresIn` option when generating the token.