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

# Authentication

> How server and user requests are authenticated, IP allowlisting and rate limits.

## Server requests: app and user parameters

[Get surveys](https://docs-saas.primeearn.com/partner-saas/surveys/get-surveys.md) is called from your server. It identifies your app and user with **query** parameters:

| Parameter | Required | Description |
| - | - | - |
| `app` | Yes | Your app hash. |
| `external_user_id` | Yes | Your ID for the user. A user is created on the first call. |
| `ip` | Yes | The user's IPv4 address (not your server's). IPv6 is not supported. |
| `output` | Yes | Always `API`. |
| `token` | If secure API mode is on | Your app API token. |

If `app`, `external_user_id`, `ip` or `output=API` is missing, the request is rejected with `401`:

```json theme={null}
{ "status": "error", "code": 1, "message": "Unauthorized [1]" }
```

[Surveys list](https://docs-saas.primeearn.com/partner-saas/surveys/surveys-list.md) is not tied to a user, so it only needs `app` and `token`.

## User requests: Bearer token

The qualification endpoints act for one user. Send the user hash `uh` from the Get surveys response as a Bearer token:

```text theme={null}
Authorization: Bearer {uh}
```

You can also send `Bearer {external_user_id}:{app}`. If secure API mode is on for your app, also send `token` in the request body - recommended if you cannot provide IPs for the whitelisting.

A missing or unknown Bearer token returns `401`:

```json theme={null}
{ "message": "Unauthenticated." }
```

## App token

The `token` must match your app API token. When secure API mode is off for your app, you can leave `token` out. A wrong token is always rejected. These checks return `400`:

| `message` | Cause |
| - | - |
| `Token mismatch` | `token` is wrong, or missing while secure API mode is on |
| `App not found` | Unknown `app` hash |
| `App is deleted` | The app was deleted |
| `Invalid request parameters` | `app` or `external_user_id` was sent as an array |

```json theme={null}
{ "status": "error", "message": "Token mismatch" }
```

## IP allowlist

If your app uses a strict IP allowlist, requests must come from one of your registered server IPs. Other requests get `403`:

```json theme={null}
{ "status": "error", "message": "IP address is not allowed" }
```

## Rate limits

| Scope | Limit |
| - | - |
| Per app and user, on Get surveys | 20 requests per minute |
| Per app and user, on Get surveys and the qualification endpoints | 40 requests per minute |
| Per app and country, on Surveys list | 60 requests per minute |

Requests over the limit get HTTP `429`. On Get surveys and the qualification endpoints the body has `"message": "too_many_requests"`.

> [!TIP]
>
> Cache Get surveys results for a short time per user instead of calling it on every page view.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.