> 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/using-basic-authentication.md).

# Using basic authentication

Instead of sending account details as body parameters, you can use basic authentication to generate a bearer token instead.

Before calling other endpoints, you need to generate an Authorization Bearer token. To retrieve your token using basic auth, simply send your account credentials in base64 encoded format within the header.

The format should be ***Basic email:password*** where email:password are encoded.

This token has a lifetime of 1 year, and is invalidated whenever a new token is generated.

The token is attached to the user credentials it was created with and as such it is recommended to create a service account for applications and use those credentials for token generation.

***

## Generate a bearer token using basic authentication

<mark style="color:green;">`POST`</mark> `/api-basic-auth`

Generate a token for use with other endpoints.

#### Header

| Name          | Value                   |
| ------------- | ----------------------- |
| Content-Type  | `multipart/form-data`   |
| Authorization | `Basic (base64 string)` |

#### Request

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

```sh
curl --location --request POST 'https://enterprise.personr.co/api/1.1/wf/api-basic-auth' \
-H "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ="
```

{% endtab %}

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

```javascript
const axios = require('axios');
const base64 = require('base-64');

const email = 'example@personr.co';
const password = 'example123';

const credentials = base64.encode(`${email}:${password}`);

const config = {
    headers: {
        'Authorization': `Basic ${credentials}`
    }
};

axios.post('https://enterprise.personr.co/api/1.1/wf/api-basic-auth', null, config)
    .then(response => {
        console.log('Response:', response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const email = 'example@personr.co';
const password = 'example123';

const credentials = btoa(`${email}:${password}`);

const headers = new Headers();
headers.append('Authorization', `Basic ${credentials}`);
headers.append('Content-Type', 'application/json');

fetch('https://enterprise.personr.co/api/1.1/wf/api-basic-auth', {
    method: 'POST',
    headers: headers
})
.then(response => response.json())
.then(data => {
    console.log('Response:', data);
})
.catch(error => {
    console.error('Error:', error);
});
```

{% endtab %}

{% tab title="Ruby" %}

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

email = "example@personr.co"
password = "example123"

credentials = Base64.strict_encode64("#{email}:#{password}")

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

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Basic #{credentials}"

response = https.request(request)
puts response.read_body
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import base64

email = 'example@personr.co'
password = 'example123'

credentials = base64.b64encode(f'{email}:{password}'.encode()).decode()

url = "https://enterprise.personr.co/api/1.1/wf/api-basic-auth"

headers = {
    'Authorization': f'Basic {credentials}'
}

response = requests.post(url, headers=headers)

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 workflow to renew your token 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/using-basic-authentication.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.
