#34916·n8n

Salesforce node (OAuth2): refresh silently drops oauthTokenData.instance_url, causing "Invalid URL" (ERR_INVALID_URL) until manual reconnect

Author: GuilleAmutioCreated Jul 24, 2026Updated Sep 28, 2026
Labelsstatus:in-linearstatus:team-assignedteam:iam

Bug Description

Self-hosted n8n (queue mode, PostgreSQL). A workflow using the Salesforce node with a Salesforce OAuth2 API credential works fine for a period (intraday token refreshes succeed), then starts failing every execution with:

NodeApiError: Invalid URL
httpCode: ERR_INVALID_URL

Manually reconnecting the credential (full OAuth authorize flow) fixes it immediately - but it breaks again after the next background token refresh cycle, in a repeatable "works after reconnect, dies again after ~a day" pattern. Same Salesforce org, different dedicated integration user/Connected App works fine on a separate (dev) n8n instance running identical n8n version/config.

Root Cause (traced from an actual failing execution)

packages/nodes-base/nodes/Salesforce/GenericFunctions.ts builds every API request URL from the credential's stored OAuth token data:

typescript
const credentials = await this.getCredentials<{ oauthTokenData: { instance_url: string } }>('salesforceOAuth2Api');
const options = getOptions.call(this, method, uri || endpoint, body, qs,
  credentials.oauthTokenData.instance_url);
...
uri: `${instanceUrl}/services/data/${SALESFORCE_API_VERSION}${endpoint}`

When oauthTokenData.instance_url is empty/undefined, this produces something like "undefined/services/data/v59.0/...", which Node's URL parser rejects with ERR_INVALID_URL - exactly the error surfaced to the user, with a stack trace rooted at GenericFunctions.ts:192 (salesforceApiRequest).

The reason instance_url goes missing: packages/core/src/execution-engine/node-execution-context/utils/request-helpers/oauth.ts, in the generic OAuth2 token-refresh path, merges old and refreshed token data like this:

typescript
const newOAuthTokenData = addExpiresAt({ ...token.data, ...newToken.data });

// If the server doesn't echo the resource back, restore it from the
// previous token data to ensure it's not lost on refresh.
if (!newOAuthTokenData.resource && token.data.resource) {
  newOAuthTokenData.resource = token.data.resource;
}

There's an explicit, deliberate fallback to preserve only the resource field if the authorization server's refresh response doesn't echo it back. There is no equivalent protection for any other non-standard field a credential type may depend on - such as Salesforce's instance_url, which the Salesforce node requires on every request but which isn't part of the generic OAuth2 core.

If a refresh-grant response from the auth server ever omits instance_url (for whatever server-side reason - scope config, session policy, etc.), n8n has no fallback and the credential is left permanently missing instance_url in its stored oauthTokenData until a full manual reconnect (fresh authorization-code grant) repopulates it. Every Salesforce node call fails with "Invalid URL" in the meantime, regardless of whether the access/refresh token itself is otherwise valid.

This looks like the same underlying issue reported (without root cause) in #19945 - "Salesforce OAuth not working properly", which has multiple independent reporters describing the identical "fails once a day, only fixed by reconnect" symptom, unresolved since Sept 2025.

To Reproduce

  1. Create a Salesforce OAuth2 API credential (Connected App / External Client App, refresh token granted).
  2. Use it in a Salesforce node in a scheduled workflow.
  3. Let it run past the point where n8n performs a background OAuth2 token refresh.
  4. If the refresh-grant response from Salesforce doesn't include instance_url, every subsequent Salesforce node call fails with Invalid URL / ERR_INVALID_URL until the credential is manually reconnected.

Expected Behavior

instance_url (and arguably any other non-standard field the original token response provided, e.g. id, signature) should be preserved across a refresh the same way resource already is - i.e., in oauth.ts, fall back to the previous oauthTokenData value for these fields when the refresh response doesn't include them, rather than only doing this for resource.

Environment

  • n8n version: 2.30.4
  • Execution mode: queue (main + workers)
  • Database: PostgreSQL
  • Hosting: self-hosted (Kubernetes/Helm)
  • Credential type: Salesforce OAuth2 API (salesforceOAuth2Api)