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

# Authentication

All API requests must use HTTPS and authenticate by passing API key credentials using [HTTP Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication). Requests do this by setting the request header `Authorization: Basic <credentials>` where `credentials` is a secret token authenticating the request and associating it with a specific API key.

## Authorizing the request

Depending on your API client, you may need to take different steps to construct the `Authorization` header.

### Using a username and password

If your API client requires you to provide a username and password when using Basic Auth, use the *Username* and *Password* values provided on the API key confirmation screen. Your client will then create the `Authorization` header for you.

#### Example: Postman

Postman is an example of an API client that prompts for a username and password. The secret token isn't needed in this case and no other custom headers should be needed aside from the username and password. ![PostmanExample](https://github.com/user-attachments/assets/4bd22f50-89ed-45d1-b459-f450cc23747f)

### Manually constructing the header

Some clients, such as `curl`, require constructing the header by hand. Use the *API Secret Token* value provided on the API confirmation screen, and construct a header that looks like `Authorization: Basic <API Secret Token>`.

{% hint style="info" %}
Basic Auth requires that the request contain a header field in the form of `Authorization: Basic <credentials>`, where `<credentials>` is the Base64 encoding of the Username and Password in the format `username:password`. CiviForm does this encoding for you and provides it in the value of API Secret Token.
{% endhint %}

#### Example: curl

For a curl, you'll use the following code, but replace the URL and replace the \<api\_secret\_token> with the API secret token that is provided when API credentials are created.

```shell
curl https://staging.myciviform.gov/api/v1/checkAuth -vH "Authorization: Basic <api_secret_token>"
```

## Additional security features

Additionally, API keys have several security features beyond simply checking the ID and secret of the key. If any of the constraints specified by those features are not met, API requests will receive a 401 response code. For more information see [Api key security](/user-manual/civiform-admin-guide/manage-api-keys.md#api-key-security).

## Obtaining API credentials

The CiviForm admin creates API keys using the admin UI. See [managing API keys](/user-manual/civiform-admin-guide/manage-api-keys.md) for instructions on creating API keys and obtaining an API key's credentials.

## Testing API credentials

To test your API credentials, submit a `GET` request to `/api/v1/checkAuth` with your credentials.

With `curl`, that might look like this:

```shell
curl https://staging.myciviform.gov/api/v1/checkAuth -vH "Authorization: Basic <api_secret_token>"
```

If you receive a `200 OK` then your key is set up correctly to access CiviForm.
