Skip to content
CheckcraftDownload
Practical workflow

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

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

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 ·

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.

API call diagram: method and URL, headers, body, status and response body, logs and database

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.

Layers of an API call check: status, headers, body, calculations, logs, database

Which method where

MethodIn curlWhere you meet it
Bearer token-H "Authorization: Bearer ..."OAuth 2.0, JWT, most modern APIs
Basic-u user:passwordInternal 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.

More on curl

Section overview and all guides: curl command cheat sheet: flags and examples for APIs.

Frequently asked questions

How do I pass a Bearer token in curl?

-H "Authorization: Bearer token"; the word Bearer and the space are required.

How do I pass login and password?

-u login:password; curl builds the Basic header.

Why do I get 401 with a token?

Expired, extra whitespace, wrong header or missing Bearer; check with -v.

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 FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

curl man page and exit codes

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.

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

No account required. We will reply by email. This is a support request, not a newsletter subscription.