> For the complete documentation index, see [llms.txt](https://docs.parameter1.com/mindful-apis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.parameter1.com/mindful-apis/authentication.md).

# Authentication

There are three authentication methods available to the Mindful APIs:

1. "Magic Link" user authentication
2. "M2M" machine authentication
3. "Company" scope-limited anonymous authentication

Most use cases will use standard user authentication.

## "Magic Link" User Authentication

A user authentication token can be retrieved by:

Executing the `sendUserLoginLink` mutation on the User API. If a Mindful user exists for the supplied email address, they will receive an email with a "magic link" (containing a temporary authentication JWT in the `token` parameter).

```http
POST /user HTTP/1.1
Content-Type: application/json
Host: graphql.mindfulcms.com

{"query":"mutation { sendUserLoginLink(email: \"foo@bar.baz\")"}

```

Executing the  `loginUserFromLink` mutation on the User API while supplying the `token` from the email. This is exchanged for a longer-lived (7 days) authentication token, which you will send with subsequent requests.

```http
POST /user HTTP/1.1
Content-Type: application/json
Host: graphql.mindfulcms.com

{"query":"mutation { loginUserFromLink (loginLinkToken: \"<token-from-magic-link>\") { value }"}

```

When sending a request with user authentication, send the token using Bearer authentication:

```http
POST /user HTTP/1.1
Content-Type: application/json
X-Namespace: contoso/default
Authorization: Bearer <new-user-token>
Host: graphql.mindfulcms.com
Content-Length: 198

{"query":"query { currentUser { _id email { address } }"}
```

## "M2M" Machine Authentication

A permanent variant of a user authentication, for use in automated processes that need authentication (such as retrieving analytics, or inserting/updating data.)

You can create an M2M token by visiting your User Profile screen from the main Mindful UI menu, and selecting "Generate" under the API Token section.

{% hint style="warning" %}
Generated tokens will only ever be displayed once — and by design, cannot be retrieved again.

If you lose your token you will need to regenerate it and replace the old token in any existing integrations.

We recommend using a password manager to save the value.
{% endhint %}

<figure><img src="https://3188008229-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNxKyAp7c6mrrsMyVy8Mj%2Fuploads%2FBX16IjcGTsEAOPIWlogr%2Fimage.png?alt=media&amp;token=8c901876-6f5a-4343-8efe-1037ee838d81" alt=""><figcaption></figcaption></figure>

## "Company" Authentication

"Company" authentication allows for anonymous visitors to access sensitive data (such as advertising metrics), but only limited in scope to specific Advertising Companies.

These tokens are generated automatically within the Mindful UI, or they can be generated manually with the Utility API's `createAdvertisingCompanyAccessToken` mutation.

{% hint style="info" %}
A valid user (or machine) authentication must be present in the request to generate a company token.
{% endhint %}
