Skip to content
New: a free website for your business, live in 48 to 72 hoursWorkflow automation on n8n and Claude, built for your businessFixed price, agreed before we start · Live in 5 to 10 business days30-day money-back guarantee on every planProfessional firms · Agencies · E-commerceYou own every workflow, in your own n8nClaude API: your data is not used for trainingHuman approval on every sensitive stepFree automation audit, no obligation
PURIST
30 days
Money-back window
14 h/wk
Modeled time saved
99.97%
Uptime SLA
< 7 days
Deploy time
PURIST AI
Claude Opus 4.7 · n8n v1.71 · <80ms
What type of business are you running? I'll show you exactly which processes we'd automate first and your estimated ROI.
Powered by n8n + Claude Opus 4.7 Get my free automation plan →
n8n HTTP Request Authentication: API Keys, Bearer Tokens and OAuth2
Guides 7 min read · 1,459 words

n8n HTTP Request Authentication: API Keys, Bearer Tokens and OAuth2

How to send API keys and tokens from n8n without pasting them into the URL: predefined vs generic credentials, which generic type matches each API, and how to read 401 and 403 errors.

Steve, founder of PURIST

November 6, 2026

PURIST: Stuck on n8n? Our n8n experts fix and build workflows like this one, at a fixed price →

The HTTP Request node can call any API, but the first wall is authentication. Pasting a key into the URL or into a header field works once and then leaks into every workflow export and execution log. n8n credentials solve this: the secret is stored encrypted and the node sends it for you.

In short. If n8n already has a node for the service, choose Authentication > Predefined Credential Type and reuse that credential: it is the method n8n recommends. Otherwise choose Generic Credential Type: Header Auth for Authorization: Bearer ... or X-API-Key, Query Auth for ?api_key=, Basic Auth for username and password, OAuth2 when the API uses an authorization flow.

n8n HTTP Request Authentication: API Keys, Bearer Tokens and OAuth2: workflow diagram
Match what the API documentation says to the right n8n credential type. Illustration: PURIST.

Predefined or generic?

OptionWhenBenefit
Predefined Credential Typen8n has a node for the service (HubSpot, Google, Slack...)Reuses the same credential, handles OAuth refresh, lets you call endpoints the node does not offer
Generic Credential TypeNo native nodeYou configure the method yourself

The predefined option is the hidden gem: when the native node lacks an operation, call the API endpoint directly with the HTTP Request node using the native credential, with no extra setup.

Choosing the generic type

The generic types available are Basic auth, Custom auth, Digest auth, Header auth, OAuth1, OAuth2, Query auth and Simplified Custom Auth. Match them to the API documentation:

The API documentation saysGeneric typeConfiguration
Authorization: Bearer YOUR_TOKENHeader AuthName Authorization, Value Bearer YOUR_TOKEN
X-API-Key: YOUR_KEYHeader AuthName X-API-Key, Value YOUR_KEY
?api_key=YOUR_KEY in the URLQuery AuthName api_key, Value YOUR_KEY
Username and passwordBasic AuthUser and password
"OAuth 2.0", client ID and secretOAuth2 APIAuth URL, token URL, scopes, client ID and secret
Several headers or a body tokenCustom AuthA JSON definition of headers, query or body values

The most common mistake with bearer tokens: forgetting the word Bearer and the space before the token in the header value.

n8n HTTP Request Authentication: API Keys, Bearer Tokens and OAuth2: node settings
A bearer token stored as a Header Auth credential. Illustration: PURIST.

Import a cURL command

API documentation usually shows a cURL example. In the HTTP Request node, Import cURL fills the method, URL, headers and body for you. After importing, move any key it placed in a header into a credential and delete the plain-text header. Our cURL to n8n converter shows the result before you paste anything into n8n.

OAuth2 in two minutes

For an OAuth2 API:

  1. 1 Create the app in the provider's developer console.
  2. 2 Copy the OAuth Redirect URL shown in the n8n credential into the provider's authorised redirect URIs, character for character.
  3. 3 Paste the client ID and secret into n8n, set the scopes, and connect.

If the provider answers redirect_uri_mismatch, the two URLs differ, usually by protocol, domain or port. See fix redirect_uri_mismatch in n8n.

Reading 401 and 403 errors

  • 401 Unauthorized: the API did not accept the credential at all. Wrong key, missing Bearer, expired token, or the header name is wrong.
  • 403 Forbidden: n8n shows "Forbidden - perhaps check your credentials". The API knows who you are, but the key lacks permission or scope for this operation. The documentation suggests updating permissions or scopes, formatting the credential differently, or generating a new key with the right scopes.

Our HTTP Status Explainer lists what each code means for an automation and what to check first.

Dynamic credentials

Need a different account per customer? The documentation suggests routing with a Switch node to HTTP Request nodes that each use their own credential, using an expression in the credential field, or Custom Auth with expressions. Do not fetch secrets in a Code node: Code nodes cannot access credentials by design.

Worked example: calling an endpoint the native node does not offer

You use the native HubSpot node, but you need an endpoint it does not expose. Instead of creating a new key:

  1. 1 Add an HTTP Request node.
  2. 2 Authentication: Predefined Credential Type.
  3. 3 Credential Type: the same service as your native node, then select your existing credential.
  4. 4 Enter the endpoint URL and method from the API reference.

n8n attaches the same authentication the native node uses, including OAuth2 token refresh. This is the method n8n recommends, and it keeps one credential per service instead of several copies.

Custom Auth for unusual APIs

Some APIs need several values at once, for example a key in a header and an account ID in the query. Custom Auth takes a JSON definition:

json
{
  "headers": { "X-Api-Key": "YOUR_KEY", "X-Account": "12345" },
  "qs": { "region": "eu" }
}

Everything in it is stored encrypted with the credential. Use Simplified Custom Auth when you only need a couple of fields.

OAuth2 settings in plain words

FieldWhat to put
Grant TypeUsually Authorization Code (a user signs in) or Client Credentials (server to server)
Authorization URLThe provider's "authorize" endpoint
Access Token URLThe provider's "token" endpoint
Client ID / SecretFrom the app you created in the provider's console
ScopeThe permissions you need, separated as the provider documents
OAuth Redirect URLShown by n8n: copy it into the provider's console

Request the smallest scopes that work. If a call later returns 403, a missing scope is the first suspect.

Security habits that pay off

  • One credential per environment. A test key in the test instance, a live key in production.
  • Name credentials by purpose. "Stripe live, read only" is clearer than "Stripe 2".
  • Rotate on departures. When someone with access leaves, rotate the keys they could see.
  • Prefer read-only keys for reporting workflows.

Troubleshooting table

SymptomLikely causeFix
401 UnauthorizedWrong key, missing "Bearer ", wrong header nameRecheck the credential against the API docs
403 ForbiddenKey valid, permission or scope missingAdd the scope or permission, reconnect
Works in Postman, not in n8nHeader or query sent differentlyImport the working cURL into n8n and compare
OAuth2 stops working after daysRefresh failed or app consent revokedReconnect the credential; check the app status
redirect_uri_mismatchRedirect URL not registered exactlyCopy the OAuth Redirect URL from n8n

Production checklist

  • No secret in the URL, a header field or a Code node.
  • Predefined credentials wherever a native node exists.
  • Minimum scopes on every key.
  • One credential per environment (test and production).
  • An error branch or error workflow that alerts on 401 and 403, which often signal an expired or revoked key.

Frequently asked questions

How do I add an API key to an n8n HTTP Request?

Set Authentication to Generic Credential Type, then Header Auth (for a header such as X-API-Key or Authorization) or Query Auth (for a key in the URL), and store the key in the credential.

How do I send a bearer token in n8n?

Use Header Auth with Name Authorization and Value Bearer YOUR_TOKEN, including the word Bearer and a space.

Can I use a native node's credential in the HTTP Request node?

Yes. Choose Predefined Credential Type and select the service. This is the method n8n recommends when it is available.

What does "Forbidden - perhaps check your credentials" mean?

The API returned 403: the credential is recognised but lacks permission or scope for the request. Check the key's scopes and permissions.

What is the difference between Header Auth and Custom Auth?

Header Auth sends one header. Custom Auth can send several headers, query parameters and body values defined in JSON.

Can I use one credential in many workflows?

Yes. Credentials are shared across workflows, subject to your instance's sharing settings.

How do I authenticate with an API that needs a token from a login call first?

Some APIs need a first request to get a short-lived token. Use one HTTP Request node to log in, then pass the token to the next request with an expression, or use the OAuth2 Client Credentials flow if the API supports it.

Tags

n8nhttp requestauthenticationapi keyoauth2
Steve, founder of PURIST

Steve founded PURIST, a workflow automation studio working with n8n, Make and Claude AI, and is the point of contact on every project. Prices and features in our articles come from vendor documentation and public pricing pages. How we research and score tools.

Complete guide

Automation Tools & Platforms

11 min read n8n Code Node: 15 JavaScript Examples You Can Copy and … 8 min read n8n Code Node With Multiple Inputs: 3 Methods That Work 7 min read Fix "Cannot find module" in the n8n Code Node (npm Pack… 7 min read n8n Code Node Errors Fixed: "Code doesn't return items … 7 min read $env and Credentials in the n8n Code Node: What Works a… 7 min read n8n Code Node Binary Data: Read, Change and Return File… 7 min read Python in the n8n Code Node (n8n 2.x): Setup, Syntax an… 7 min read Fix n8n "The requested webhook is not registered" (Test… 6 min read n8n Webhook URL: Test vs Production, and How to Change … 7 min read n8n Respond to Webhook: Return JSON, Status Codes, Redi… 8 min read Secure an n8n Webhook: Header Auth, Basic Auth, JWT and… 7 min read n8n Webhook Not Working? 10 Causes and How to Fix Each … 7 min read n8n HTTP Request Pagination: Every Pattern With Working… 7 min read n8n HTTP Request Timeout and "Aborted" Errors: Causes a… 7 min read Upload and Download Files With the n8n HTTP Request Nod… 6 min read Fix ECONNREFUSED in n8n: Docker, localhost and 127.0.0.… 6 min read n8n 429 Too Many Requests: Batching, Retries and Rate L… 6 min read Fix redirect_uri_mismatch for n8n OAuth2 Credentials (G… 7 min read n8n Expression Errors Fixed: "Referenced node is unexec… 6 min read Anatomy Claude skill: what it is, how to install it, an… 5 min read How to explain a business process with the Anatomy skil… 5 min read Anatomy vs Mermaid vs Excalidraw: which to explain a wo… 14 min read n8n LinkedIn Job Automation: Auto-Apply, Track, and Fol… 16 min read n8n HTTP Request Node: Complete Documentation and Examp… 18 min read The future of automation: how our engineering team is s… 8 min read n8n vs Make vs Zapier: the honest comparison your busin… 11 min read n8n vs Make vs Zapier: an honest comparison for product… 7 min read Webhook vs polling: the architecture decision that dete… 24 min read n8n tutorial: build your first production workflow in u… 26 min read The 9 best Zapier alternatives in 2026: an honest ranki… 21 min read Make.com tutorial: build powerful automations without c… 19 min read Automation consultant vs DIY: how to decide what is rig… 14 min read n8n Self-Hosted vs Cloud: The Complete Decision Guide (… 15 min read 5 Zapier Free Alternatives That Handle Real Production … 15 min read WhatsApp Business Automation With n8n: Build a 24/7 Cus… 17 min read Google Workspace Automation: 15 Workflows for Sheets, D… 16 min read Claude AI for Business Automation: What It Does, What I… 15 min read Airtable Automation With n8n: 10 Workflows That Make Yo… 15 min read Droven.io AI Automation Tools: Full Review and Best Alt… 14 min read Droven.io RPA and Business Automation: An Honest 2026 R… 15 min read Enterprise Workflow Automation: The Complete Guide for … 13 min read Document Workflow Automation: Software, Implementation,… 14 min read Marketing Automation Workflow: From Content Creation to… 16 min read Ad Campaign Workflow Data Model and SDR Inbound Pipelin… 14 min read ComfyUI Workflows for Business: Product Photography, Ma… 13 min read GPT-5.2 for Business Workflows and the spec-workflow-mc… 17 min read ServiceNow vs IBM BAW vs n8n: Enterprise Workflow Autom… 16 min read 9 Best Workflow Automation Tools for Small Business in …

Keep reading

More from the blog.

All articles

From audit to deployment

Experience the automation
these articles are about.

Get my free automation plan →