# curl with authorization: Bearer token, Basic, API key and headers

Source: https://checkcraft.ru/en/guides/curl-authorization-header.html · updated 2026-12-02

How to pass auth in curl: the Authorization: Bearer header with a token, Basic via -u user:password, an API key in a header or parameter, cookies.

Practical workflow

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. [Download, no sign-up →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

Most APIs require auth, and in curl it goes in a header or the -u flag. A Bearer token goes in the Authorization header, login and password via -u, an API key in the header named in the service docs. Below are working commands and the common mistakes that make the server answer 401.

Checkcraft · 24 November 2026

Get help with your first test →

## Bearer token

Write the full header: -H "Authorization: Bearer your_token". The word Bearer and the space are required. Keep the token in an environment variable and substitute it so it stays out of shell history and screenshots.

## Basic and API key

For Basic use -u login:password; curl encodes the pair in Base64 itself. Leave the password out and curl asks for it interactively. Pass an API key the way the service requires: usually a header like X-API-Key, sometimes a URL parameter, but parameters end up in server logs.

Repeating checks like this by hand? Checkcraft saves them and reruns them in one click. [Download Free →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

## Why 401 comes back

Most often the token expired, was copied with an extra space or newline, sent in the wrong header or without the word Bearer. On Windows quotes sometimes eat part of the header. Use -v to see the header actually sent.

## Commands with auth

```
# Bearer токен из переменной окружения
export TOKEN="eyJhbGciOi..."
curl -H "Authorization: Bearer $TOKEN" https://api.example.com/v1/orders

# Basic: логин и пароль
curl -u "user:password" https://api.example.com/v1/orders

# API-ключ в заголовке
curl -H "X-API-Key: $API_KEY" https://api.example.com/v1/orders

# POST с токеном и JSON
curl -X POST https://api.example.com/v1/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"sku":"MON-24","qty":2}'

# cookie сессии
curl -b "session=abc123" https://app.example.com/api/profile
```

On Windows variables and quotes differ; see [curl on Windows and PowerShell](https://checkcraft.ru/en/guides/curl-windows-powershell.html).

## Which method where

| Method | In curl | Where you meet it |
|---|---|---|
| Bearer token | -H "Authorization: Bearer ..." | OAuth 2.0, JWT, most modern APIs |
| Basic | -u user:password | Internal services, 1C, older APIs |
| API key | -H "X-API-Key: ..." | Public service APIs |
| Cookie | -b "name=value" | Web app APIs after login |

## Check what was sent

-v prints the sent headers on lines starting with a greater-than sign. An empty Authorization or a stray character means a variable or quoting mistake. A JWT expiry can be checked by decoding it: [JWT decoder](https://checkcraft.ru/en/guides/jwt-decode-online.html).

## More on curl

Section overview and all guides: [curl command cheat sheet: flags and examples for APIs](https://checkcraft.ru/en/guides/curl-cheat-sheet.html).

- [curl errors: codes 6, 7, 22, 28, 35, 60 and how to fix them](https://checkcraft.ru/en/guides/curl-errors.html)
- [curl on Windows and PowerShell: how to run it and why commands fail](https://checkcraft.ru/en/guides/curl-windows-powershell.html)
- [Download a file with curl: -o, -O, redirects and resume](https://checkcraft.ru/en/guides/curl-download-file.html)
- [curl through a proxy: -x, environment variables, SOCKS and no_proxy](https://checkcraft.ru/en/guides/curl-proxy.html)
- [PHP cURL: GET and POST requests with JSON, headers and error handling](https://checkcraft.ru/en/guides/php-curl.html)

Next step

## Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

[Download Free](https://checkcraft.ru/en/download-checkcraft.html#free-download) · [Download and first run](https://checkcraft.ru/en/download-checkcraft.html)

No sign-up or email needed, the archive is ready in a couple of minutes. See the [edition limits](https://checkcraft.ru/en/pricing.html).

## References

[curl man page and exit codes](https://curl.se/docs/manpage.html)

## Continue with a related task

[Configure API request authentication](https://checkcraft.ru/en/guides/api-request-authorization.html) · [401 Unauthorized in an API and Postman: why access is denied](https://checkcraft.ru/en/guides/api-401-error.html) · [cURL examples: GET and POST requests with JSON on Linux, Windows and PowerShell](https://checkcraft.ru/en/guides/curl-post-json.html) · [Decode a JWT online: expiry, payload and signature](https://checkcraft.ru/en/guides/jwt-decode-online.html) · [curl errors: codes 6, 7, 22, 28, 35, 60 and how to fix them](https://checkcraft.ru/en/guides/curl-errors.html)

Start with the linked example and compare its result with your own test requirement.

Ask a person

## Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

[Ask in Telegram](https://t.me/checkcraftchat)Send an email

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

Page card: /ai/pages/en/guides/curl-authorization-header.md
