Guides / n8n × HubSpot / Authentication

HubSpot API key removed: migrating a hapikey integration to a private app token

The hapikey query parameter is gone. What replaces it, the exact header change, why a working curl can still fail inside a connector, and how to prove no forgotten job is still using the old path.

Illustrated troubleshooting diagram for HubSpot API key removed: how to migrate a hapikey integration to a private app token.
401 Unauthorized — {"status":"error","category":"INVALID_AUTHENTICATION","message":"Authentication credentials not found..."} on a request still sending ?hapikey=
Short answer: HubSpot sunset the hapikey query parameter. The replacement for a single-portal integration is a private app access token (pat-na1-…) sent as an Authorization: Bearer header — never as a query parameter. Grant the private app only the scopes the integration actually calls, store the token server-side, and audit every cron job, workflow export and admin script for the retired parameter. Authentication and endpoint-version migration are two separate jobs; fixing one does not fix the other.

What actually replaces hapikey

There are two replacements and choosing the wrong one costs a rebuild. A private app is the right answer when the integration talks to exactly one HubSpot portal that you control: HubSpot issues a long-lived access token beginning pat-na1-, you paste it into a secret store, and every request carries it in an Authorization header. There is no token exchange, no refresh cycle and no consent screen.

OAuth is the right answer when other HubSpot customers install your software, because each installing portal has to grant consent and receives its own tokens. Distributing one private app token to several customers is not a shortcut around OAuth — it hands every customer the same credential scoped to your portal, which is a security incident waiting for a support ticket.

The exact change in the request

Mechanically the migration is one line. The key moves out of the URL and into a header, which also removes it from proxy logs, analytics, browser history and any error report that echoes the failing URL. That is a meaningful reduction in accidental disclosure even though the token still needs proper secret management.

The subtlety is that a private app token is presented exactly the way an OAuth access token is — Bearer, in the Authorization header. Client code written for OAuth needs no changes beyond where the token comes from.

# Before (sunset — returns 401 INVALID_AUTHENTICATION)
curl "https://api.hubapi.com/crm/v3/objects/contacts?hapikey=abc123&limit=1"

# After
curl https://api.hubapi.com/crm/v3/objects/contacts?limit=1 \
  -H "Authorization: Bearer pat-na1-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# Node / n8n Code node
const res = await fetch("https://api.hubapi.com/crm/v3/objects/contacts?limit=1", {
  headers: {
    Authorization: "Bearer " + token,
    "Content-Type": "application/json"
  }
});

Classify the response before touching the credential

Four status codes come up during this migration and only one of them is about the token itself. A 401 with category INVALID_AUTHENTICATION means the token is missing, malformed, revoked, or still being sent as hapikey. A 403 with MISSING_SCOPES means the token is valid and the private app simply was not granted the scope that endpoint requires — the fix is in HubSpot's app settings, not in the credential. A 404 usually means the route itself was retired, which no new token will revive. A 429 is rate limiting and has nothing to do with authentication.

The 403 case catches people out most, because the smoke test — a GET against a list endpoint — passes on read scopes while the first write fails. Test one read, one create, one update and one association separately before declaring the migration done.

# 401 — credential state
{"status":"error","category":"INVALID_AUTHENTICATION",
 "message":"Authentication credentials not found..."}

# 403 — token fine, scope missing (fix in HubSpot, not in the client)
{"status":"error","category":"MISSING_SCOPES",
 "message":"This app hasn't been granted all required scopes...",
 "context":{"requiredScopes":["crm.objects.contacts.write"]}}

# 404 — retired route; needs a v3 migration, not a new token
# 429 — rate limit; see the burst and daily-cap guides

When curl works and the connector does not

A token that succeeds from the terminal and fails inside n8n, Zapier or Make almost always means the connector is still constructing the old request. The common causes are a credential type that appends an API key as a query parameter, a node-level header that overwrites Authorization with its own value, or a second HubSpot credential left configured on another node in the same workflow that still holds the legacy key.

Inspect the actual outgoing request rather than the credential form. In n8n, the execution data for an HTTP Request node shows the URL it built; if the query string still contains hapikey, the credential type is wrong regardless of what the token field contains.

The trap: replacing hapikey with Bearer while keeping a retired v1 or v2 endpoint. Authentication then succeeds and the route still 404s, which reads like a broken token and is not one.

Prove no legacy consumer remains

The migration is not finished when the main client is updated. Search application code, environment files, workflow JSON exports, cron definitions, serverless configuration, test fixtures and observability queries for hapikey and api_key — without printing the value into command output. Mark each hit as production, staging or unknown, and resolve the unknowns; a quarterly export script nobody owns is the classic last consumer.

A durable safeguard is a release check that rejects any outbound HubSpot request whose URL contains the retired parameter, logging the caller without logging the key. That converts a silent failure six months from now into a visible one on the next deploy. Record the private app's owner, portal, scope list and rotation date in the service inventory at the same time, so the next rotation is an operation rather than an investigation.

  • Token is in Authorization: Bearer, never in the query string.
  • Scopes cover every operation the integration performs, not just reads.
  • One read, one create, one update and one association each verified.
  • Repo, workflow exports, cron and serverless config searched for hapikey and api_key.
  • Old credential revoked after the overlap window, and the revocation confirmed in logs.

Rotating the token without downtime

A private app's token can be rotated from the app's settings, and the old value stops working the moment the new one is issued — there is no overlap window built into the mechanism. If the integration cannot tolerate a gap, create a second private app in the same portal with identical scopes, cut consumers over to it one at a time, and delete the first app once nothing is calling it. That gives you a real overlap at the cost of one extra app in the portal, and it also lets you roll back instantly if the new credential turns out to be missing a scope.

Where a brief gap is acceptable, schedule it. Deploy the new token through the same secret path the application already reads, restart any worker that cached the value in an environment variable at start-up, and watch the error rate for the first few minutes rather than assuming success from a clean deploy. Long-lived n8n instances and queue workers are the usual stragglers here — they hold the old value in memory and keep failing after everything else has recovered.

Log a credential alias rather than the secret. A string such as hubspot-prod-2026-09 tells you which credential a failing request used without putting any part of the token into a log aggregator, and it makes the next rotation traceable in a way that a masked value never is.

Where these facts come from