On this page

FusionAuth provides REST APIs for login, registration, and User management. The Admin UI uses the same APIs, so you can do anything in the Admin UI through an API.

Before you call an API, read about API Authentication and API Errors.

The following video shows how to call an API:

Play

APIs#

Unless an API documents otherwise, the API expects a JSON request body. Set the Content-Type header on every request with a body:

Content-Type Header
Content-Type: application/json

OpenAPI Specification

Learn about the FusionAuth OpenAPI Specification, which allows you to use OpenAPI tooling to interact with FusionAuth.

Authenticate with our APIs

Learn how the FusionAuth APIs authenticate requests.

Configure CORS

How to set up and use the FusionAuth API Explorer.

Error Responses

Learn about the error response that is returned from FusionAuth APIs.

API Endpoints Guarded by API Keys

A complete reference of all Fusionauth REST API Endpoints that leverage API Keys with their supported HTTP methods.

CIMD Domain OAuth Scopes

Learn about the APIs for creating, retrieving, updating and deleting the custom OAuth scopes of a CIMD domain.

Data Types

Learn about the different data types used by FusionAuth.

Event Log

Learn about the APIs for searching and retrieving event logs.

Hosted Backend

Learn about the APIs that allow you to perform OAuth2 Authorization Code Flow login, logout, and refresh for applications.

Identity Verify

Learn about the APIs for starting, sending, and completing identity verification.

Integration

Learn about the APIs for retrieving and updating integrations.

Message Template

Learn about the APIs for creating, retrieving, updating and deleting message templates.

OAuth Scopes

Learn about the APIs for creating, retrieving, updating and deleting OAuth scopes.

Reactor

Learn about the APIs for activating, deactivating, and retrieving the status of a FusionAuth Reactor license.

Tenant Manager

Learn about the APIs for retrieving and updating Tenant Manager configuration.

User Action

Learn about the APIs for invoking a User Action on a User.

User Action Reason

Learn about the APIs for creating, retrieving, updating and deleting user action reasons.

Webhook Event Log

Learn about the APIs for searching and retrieving webhook event and attempt logs.

Caution

Note: Null values in JSON are not allowed on any of the FusionAuth APIs. If you are looking to pass in a null value, simply omit it from your request instead. This will allow FusionAuth to handle default values correctly.

Status Codes#

Each API page lists the status codes that the API returns, with a reason for each code. The following status codes apply to most APIs:

Code Description
200 The request succeeded. The response body contains JSON unless the API documents otherwise.
400 The request isn't valid. The response contains an Errors JSON object with the specific errors.
401 FusionAuth didn't authorize the request. The Authorization header is missing, the API key isn't valid, or the API key doesn't have permission for this endpoint and method. The response is empty. For more information, see Unauthorized Responses.
404 The requested object doesn't exist. The response is empty.
405 The URI doesn't allow the HTTP method of the request. For example, when an API supports only POST and you send a GET request, FusionAuth returns 405. The response is empty.
413 The request body is larger than the maximum request size, which is 128 MB by default. The response is empty. For more information, see fusionauth-app.http.max-request-size in the Configuration reference.
500 FusionAuth had an internal error and logged a stack trace in the FusionAuth log files. The response usually contains an Errors JSON object with the [Exception] general error code. On MySQL, a data field larger than the database column also returns 500. For more information, see Data Field Sizes. For any other 500 response, open a GitHub Issue.
501 FusionAuth doesn't implement the HTTP method of the request.
503 FusionAuth can't complete the request because of the current rate of requests. Retry the request later.
512 A lambda invocation failed during the API request. FusionAuth creates an Event Log with details of the exception. To view the Event Log, navigate to System -> Event Log .

The PATCH HTTP Method#

FusionAuth supports the following PATCH options. To choose an option, set the Content-Type header of the request:

Option Content-Type Array Behavior Available Since
Original application/json Appends to the existing array, except where an API documents otherwise. An empty array leaves the existing array unchanged. 1.12.0
JSON Patch (RFC 6902) application/json-patch+json Operations in the request describe each change. 1.39.0
JSON Merge Patch (RFC 7396) application/merge-patch+json An array in the request replaces the existing array. 1.39.0

The client libraries support only the original option. FusionAuth may deprecate the original option in the future. Each API page documents the array fields that don't append. To change an array predictably without JSON Patch or JSON Merge Patch, GET the object, then PUT the full object.

When a request changes only object fields, and no arrays, all PATCH options produce the same result.

PATCH Example#

The following examples remove the dev role from a Group that has the roles ceo and dev. Each example starts from the following Group:

Original Group JSON
{
  "group": {
    "data": {},
    "id": "88c5ab6b-f3ea-4d37-91eb-1261d9cd7b07",
    "insertInstant": 1663971044647,
    "lastUpdateInstant": 1663971044647,
    "name": "Paid employees",
    "roles": {
      "85a03867-dccf-4882-adde-1a79aeec50df": [
        {
          "id": "0a15cfdd-e231-4de4-9411-6d1015e05d99",
          "insertInstant": 1663701174145,
          "isDefault": false,
          "isSuperRole": false,
          "lastUpdateInstant": 1663701174145,
          "name": "ceo"
        },
        {
          "id": "52fc8fe4-0afb-4040-903c-234e20271cf6",
          "insertInstant": 1663701174145,
          "isDefault": false,
          "isSuperRole": false,
          "lastUpdateInstant": 1663701174145,
          "name": "dev"
        }
      ]
    },
    "tenantId": "30663132-6464-6665-3032-326466613934"
  }
}

Each example produces the following Group:

Resulting Group JSON
{
  "group": {
    "data": {},
    "id": "88c5ab6b-f3ea-4d37-91eb-1261d9cd7b07",
    "insertInstant": 1663971044647,
    "lastUpdateInstant": 1663972082307,
    "name": "Paid employees",
    "roles": {
      "85a03867-dccf-4882-adde-1a79aeec50df": [
        {
          "id": "0a15cfdd-e231-4de4-9411-6d1015e05d99",
          "insertInstant": 1663701174145,
          "isDefault": false,
          "isSuperRole": false,
          "lastUpdateInstant": 1663701174145,
          "name": "ceo"
        }
      ]
    },
    "tenantId": "30663132-6464-6665-3032-326466613934"
  }
}

Original#

With the original PATCH method, from before 1.39.0, the safest way to remove the dev role is to GET the Group, remove the role from the roleIds array, and PUT the full Group:

PUT Request JSON
{
  "group": {
    "name": "Paid employees",
    "data": {}
  },
  "roleIds": [
    "0a15cfdd-e231-4de4-9411-6d1015e05d99"
  ]
}

JSON Patch#

JSON Patch uses operations to add, remove, replace, move, copy, and test values in a JSON object. For the full list of operations, see RFC 6902. To build a request, try the JSON Patch builder.

Send a PATCH request with a Content-Type of application/json-patch+json and the following body:

JSON Patch Request JSON
[
  {
    "op": "remove",
    "path": "/roleIds/1"
  }
]

The remove operation deletes the second value of the roleIds array, which holds the dev role. To find the index of the value, you might need a separate GET request first.

One JSON Patch request can make several precise changes to an object. The request body is a list of operations, so the body doesn't match the structure of the object you change.

JSON Merge Patch#

JSON Merge Patch updates an object with a body that matches the structure of the object. For the full merge behavior, see RFC 7396.

Send a PATCH request with a Content-Type of application/merge-patch+json and the following body:

JSON Merge Patch Request JSON
{
  "roleIds": [
    "0a15cfdd-e231-4de4-9411-6d1015e05d99"
  ]
}

The roleIds array in the request replaces the existing array, which removes the dev role.

Explore the APIs#

To try the APIs, use a self-hosted instance or the Sandbox. For sample requests, see the FusionAuth Postman collection.

Backwards Compatibility#

FusionAuth keeps APIs and features backwards compatible when possible. Before FusionAuth removes an API or feature, FusionAuth deprecates the API or feature first. For more information, see the Deprecation Policy.

Troubleshooting#

When your API call isn't working, taking the following steps can help you troubleshoot it.

Use the REST API directly. While the client libraries are useful abstractions, removing them helps narrow down the issues. Curl or wget are great choices.

When using a command line tool like curl, make sure you set the headers appropriately. These headers are commonly forgotten:

  • Authorization: the API key in most cases. Review the API Authentication documentation for more information.
  • Content-type: this is almost always application/json for any call which is not a GET request. This header can be omitted for a GET request. If you don't specify this header when making a non-GET API call, you will see an unexpected error.
  • X-FusionAuth-TenantId: only required when you have two or more tenants and the tenant cannot be inferred from the request or API key. However, you can always provide this header.

Additionally, it can be helpful to copy and paste the JSON body from the documentation for the call you are trying to debug.

When FusionAuth returns a 401, confirm that the API key has the required permissions. Repeat the request with an API key that has no endpoint permissions and no Tenant to check the headers and body. For a list of causes, see Unauthorized Responses.

Ensure you are making requests to the correct host and that your proxy, if using one, passes API requests correctly. When troubleshooting, call the FusionAuth instance directly if possible. This removes the proxy, yet another possible source of issues.

401s With New API Keys#

FusionAuth caches API keys for faster lookups. Multi-node deployments share the cache through an internal distributed cache and notifications. A new API key becomes usable after FusionAuth updates the cache, usually in less than one second. When communication between nodes fails, the update can take up to 60 seconds.

When you create an API key with the API Keys API and use the API key right away, FusionAuth can return a 401. A 401 usually means the API key isn't valid. In this case, the 401 means the new API key isn't usable yet.

To work around the delay, retry the request with exponential backoff.

Errors After Configuration Changes#

New configuration can take a few seconds to apply

FusionAuth caches configuration, such as Applications, Identity Providers, Tenants, and Keys. After you create or update configuration, FusionAuth reloads the cache in the background. When you make many changes in a short time, FusionAuth batches the reloads, and a reload can take a few seconds.

Until the reload finishes, requests that use the new configuration can fail or use the old configuration. For example:

  • The Token endpoint returns invalid_client for a new Application.
  • The Identity Provider Login API returns [InvalidIdentityProviderId] for a new Identity Provider.
  • A login uses the old settings of an updated Identity Provider.

When you script setup with the API, retry failed requests with exponential backoff, or wait after the last configuration change.