Issue
I have APIKeyHeader description
Api is made with FastApi.
I've tried different ways like
curl -X GET -H "X-Access-Token: <token>" "https://example/v1/method/"
curl -X GET "https://example/v1/method/" --header '{"X-Access-Token": "token"}'
And the answer is the same: {"detail": "Could not validate credentials"} but I know that token is correct.
P.S. new to curl, please could you describe my mistake in detail
Solution
You can use
curl -X GET "https://example/v1/method/" -H "Authorization: Bearer TOKEN_HERE"
Let's assume that I have an endpoint /users/me
, if I send an HTTP request to that endpoint with the cURL command above.
curl -X GET "http://127.0.0.1:8000/users/me" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDY1ODQwNDEtYzYwYi00NDg4LWEyYzctZmRkZmQxNWI0NDNkIiwiYXVkIjoiZmFzdGFwaS11c2VyczphdXRoIiwiZXhwIjoxNTk1NzA3ODYyfQ.yutytBX0hmv0MJy5BMSfGSBqrPvFzKqLq_-quEgNyF4"
It works perfectly.
Out: {"id":"06584041-c60b-4488-a2c7-fddfd15b443d","email":"[email protected]","is_active":true,"is_superuser":false}
Answered By - Yagiz Degirmenci Answer Checked By - Mary Flores (WPSolving Volunteer)