> For the complete documentation index, see [llms.txt](https://manual.personr.co/api-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.personr.co/api-documentation/getting-started/generating-an-authentication-token.md).

# Generating an authentication token

Let's start by generating an Authorization Bearer token to use with subsequent endpoints.

Every endpoint needs an Authorization Bearer token. There are two kinds:

* **Workspace API key (recommended for production).** Generated in the dashboard by an administrator. It's locked to one workspace, so every call made with it runs there, even when people on your team switch workspace.
* **Personal token.** Generated with your own login, through the dashboard or the `/api-token-generate` endpoint below. It follows your user, so calls run in whichever workspace you're currently switched to. Use it for testing.

Both kinds are valid for 1 year and are sent the same way: `Authorization: Bearer YOUR_TOKEN`.

***

## Workspace API keys

A workspace API key belongs to a dedicated API user that Personr creates for the workspace. That user can't sign in to the dashboard and can't switch workspace, so integrations keep working no matter what your team does in the dashboard.

**To generate a workspace API key:**

1. Switch to the workspace the integration should use.
2. Go to **Dev Space > Tokens**.
3. Under **Workspace API key**, select **Generate workspace key**.
4. Copy the key straight away and store it somewhere safe.

Only administrators can generate a workspace key. The key is shown once: it's cleared from your account when you copy it, or 15 minutes after it was generated, whichever comes first.

{% hint style="info" %}
Each workspace has its own key. If you use several workspaces, generate a key in each one and use the matching key for each integration.
{% endhint %}

{% hint style="warning" %}
A workspace API key can't call `/api-change-workspace`. To work in another workspace, use that workspace's own key.
{% endhint %}

***

## Generate a personal bearer token

To retrieve a personal token, send your account credentials as body parameters. This works like logging in to the Personr platform, but instead of being redirected to your dashboard, you receive a token you can use to call other endpoints.

A personal token is valid for 1 year, and is invalidated whenever a new personal token is generated for the same user.

The token is attached to the user it was created with, and calls run in the workspace that user is currently switched to. For production integrations, use a [workspace API key](#workspace-api-keys) instead.

<mark style="color:green;">`POST`</mark> `/api-token-generate`

Generate a token for use with other endpoints.

**Header**

| Name         | Value                 |
| ------------ | --------------------- |
| Content-Type | `multipart/form-data` |

**Body**

| Name       | Type   | Description                                          |
| ---------- | ------ | ---------------------------------------------------- |
| `email`    | string | The email you use to login to the Personr account    |
| `password` | string | The password you use to login to the Personr account |

#### Request

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://enterprise.personr.co/api/1.1/wf/api-token-generate' \
--form 'email="example@personr.co"' \
--form 'password="example123"'
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('email', 'example@personr.co');
data.append('password', 'example123');

var config = {
  method: 'post',
maxBodyLength: Infinity,
  url: 'https://enterprise.personr.co/api/1.1/wf/api-token-generate',
  headers: { 
    ...data.getHeaders()
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var form = new FormData();
form.append("email", "example@personr.co");
form.append("password", "example123");

var settings = {
  "url": "https://enterprise.personr.co/api/1.1/wf/api-token-generate",
  "method": "POST",
  "timeout": 0,
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "uri"
require "net/http"

url = URI("https://enterprise.personr.co/api/1.1/wf/api-token-generate")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
form_data = [['email', 'example@personr.co'],['password', 'example123']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://enterprise.personr.co/api/1.1/wf/api-token-generate"

payload={'email': 'example@personr.co',
'password': 'example123'}
files=[

]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "success",
  "response": {
    "token": "bus|4242424242424x424242424242424242|4343434343434x434343434343434343",
    "user_id": "4242424242424x424242424242424242",
    "expires": 31536000
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "statusCode": 400,
    "reason": "INVALID_LOGIN_CREDENTIALS",
    "message": "We didn’t find an account with those login credentials",
    }
```

{% endtab %}
{% endtabs %}

In the response, you'll receive:

* The bearer token
* The unique user id
* The expiration time of your token, expressed in seconds.

{% hint style="info" %}
Remember to include your token in the header of every subsequent API call, in the format **Authorization: Bearer YOUR\_TOKEN**
{% endhint %}

{% hint style="info" %}
Don't forget to set up a reminder to renew your token, or generate a new workspace key, before it expires.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://manual.personr.co/api-documentation/getting-started/generating-an-authentication-token.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
