# REST API Authentication

`Fluent Forms Core`

The Fluent Forms REST API lives under the `fluentform/v1` namespace:

```
https://your-site.com/wp-json/fluentform/v1/
```

Every endpoint needs a logged-in WordPress user who holds the Fluent Forms permission the endpoint checks. There are two ways to sign a request.

## Application Passwords

Use an Application Password for scripts, servers and other sites. Create one under **Users → Profile → Application Passwords**, then send it with HTTP Basic auth:

```bash
curl https://your-site.com/wp-json/fluentform/v1/forms \
  -u 'admin:abcd efgh ijkl mnop qrst uvwx'
```

```php
$response = wp_remote_get('https://your-site.com/wp-json/fluentform/v1/forms', [
    'headers' => [
        'Authorization' => 'Basic ' . base64_encode('admin:abcd efgh ijkl mnop qrst uvwx'),
    ],
]);
```

- WordPress accepts Application Passwords over HTTPS only, except on a local development site.
- The request runs as that user, with that user's Fluent Forms permissions.
- Create a dedicated user with only the permissions the integration needs, rather than using an administrator.

## Cookie and nonce

Use the logged-in browser session for JavaScript that runs inside WordPress, such as an admin screen of your own. Send the `wp_rest` nonce in the `X-WP-Nonce` header.

`wp.apiFetch` does this for you. List `wp-api-fetch` as a dependency of your script:

```js
const forms = await wp.apiFetch({ path: '/fluentform/v1/forms' });
```

Without `wp.apiFetch`, print the nonce with `wp_create_nonce('wp_rest')` and send it yourself:

```js
const response = await fetch('/wp-json/fluentform/v1/forms', {
    headers: { 'X-WP-Nonce': window.acmeSettings.restNonce },
    credentials: 'same-origin',
});
```

A request with the cookie but no valid nonce is treated as logged out.

## Permissions

Each endpoint is guarded by a policy, which checks one or more Fluent Forms permissions. Each [endpoint page](/api/endpoints/) and the [interactive reference](/api/reference/) list the permission an endpoint checks.

| Permission | Lets the user |
| --- | --- |
| `fluentform_dashboard_access` | Open Fluent Forms and see the forms list |
| `fluentform_forms_manager` | Create, edit and delete forms and their settings |
| `fluentform_entries_viewer` | View entries and reports |
| `fluentform_manage_entries` | Change, delete and annotate entries |
| `fluentform_view_payments` | View payments and transactions |
| `fluentform_manage_payments` | Change payments, such as refunds |
| `fluentform_settings_manager` | Change global settings and integrations |
| `fluentform_full_access` | Everything, including managing other users' permissions |

- Administrators (`manage_options`) and users with `fluentform_full_access` pass every check.
- Other users get permissions under **Global Settings → Permissions** (**Managers** before 7.0).
- A manager can be limited to specific forms. For an endpoint with a `{form_id}` in its URL, or a `form_id` parameter, the check is for that form.

## Errors

A request that fails the check gets the standard WordPress REST error:

```json
{
  "code": "rest_forbidden",
  "message": "Sorry, you are not allowed to do that.",
  "data": { "status": 403 }
}
```

The status is `401` when the request is not signed in, and `403` when the user lacks the permission.

## PUT, PATCH and DELETE

Some hosts and firewalls block these methods. Send the request as `POST` with an `X-HTTP-Method-Override` header instead. WordPress treats it as the method you name:

```bash
curl -X POST https://your-site.com/wp-json/fluentform/v1/submissions/42/notes/7 \
  -u 'admin:abcd efgh ijkl mnop qrst uvwx' \
  -H 'X-HTTP-Method-Override: DELETE'
```
