Hi everyone, I’m running into an issue with the HTTP Request node. I’m trying to call an API using an API key, but I keep getting a 401 Unauthorized response.
My workflow is:
Set → HTTP Request
In the Set node, I store the API key:
{
“api_key”: “123456789”
}
Then in the HTTP Request node, I add it to headers like this:
{
“Authorization”: “Bearer {{$json.api_key}}”
}
But the API keeps returning:
{
“error”: “Unauthorized”
}
Describe the problem/error/question
I’m not sure if:
The header format is wrong
The API expects it in a different place (query/body)
Or n8n is not passing the value correctly
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
For Bearer tokens better to use Bearer Auth type ( Credentials >> Generic >> Bearer Auth).
Do not specify the Header Auth in the cleartext. Moreover, it may not work, as you are not building a proper JSON object. It will break if your password has, e.g., double quotes.
ran into this exact same thing with a stripe api call last week — the header format is super picky depending on the api. barn4k’s right though, Bearer Auth credential is way better than hardcoding it in the header, avoids escaping issues
Thanks, both of these helped. I’ll first try using Bearer Auth via credentials, and if that doesn’t work I’ll double-check the API’s required header format. Appreciate the guidance from both sides