Skip to content

fix(salesforce): fall back to userinfo endpoint when instance_url missing from credentials#272

Open
Shubhank-Jonnada wants to merge 2 commits intomasterfrom
fix/salesforce-instance-url-fallback
Open

fix(salesforce): fall back to userinfo endpoint when instance_url missing from credentials#272
Shubhank-Jonnada wants to merge 2 commits intomasterfrom
fix/salesforce-instance-url-fallback

Conversation

@Shubhank-Jonnada
Copy link
Copy Markdown
Contributor

Summary

The Salesforce integration was intermittently failing with instance_url not found in credentials or metadata across all actions. The platform's OAuth layer does not always forward instance_url in the credentials dict — most notably after a token refresh, where only standard OAuth fields are returned. This fix makes the integration self-sufficient: when instance_url isn't available through the normal channels, it derives it from Salesforce's /services/oauth2/userinfo endpoint using the access token that's always present.

Root Cause

_get_token_and_instance was synchronous and raised immediately if instance_url wasn't found in credentials, context.metadata, or SALESFORCE_INSTANCE_URL. After a token refresh the platform reconstructs credentials from the refresh response, which may omit non-standard fields like instance_url, causing every action to fail until the user reconnected.

Changes

  • salesforce/salesforce.py — made _get_token_and_instance async; added _resolve_instance_url fallback that calls https://login.salesforce.com/services/oauth2/userinfo and parses urls.rest to extract the instance hostname; updated all 7 call sites to await

Behaviour

Scenario Before After
instance_url in credentials Works Works (unchanged path)
instance_url in metadata/env Works Works (unchanged path)
instance_url missing (e.g. post-refresh) Fails with reconnect error Fetches from userinfo endpoint transparently

Notes

  • The happy path (instance_url present) has zero extra API calls — the fallback only fires when needed
  • Unit tests are unaffected — they set ctx.metadata["instance_url"] which still resolves on the second check
  • No app-side or platform changes required

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

🔍 Integration Validation Results

Commit: 204849a80ff65ac28b0d1cb50d76cee326230b72 · chore(salesforce): bump version to 2.0.0
Updated: 2026-04-27T22:09:28Z

Changed directories: salesforce

Check Result
Structure ✅ Passed
Code ✅ Passed
Tests ✅ Passed
README ✅ Passed
Version ✅ Passed
✅ Structure Check output
Validating 1 integration(s)...

============================================================
Integration: salesforce
============================================================
✅ All checks passed!

============================================================
SUMMARY
============================================================
Integrations validated: 1
Total errors: 0
Total warnings: 0

✅ All validations passed!
✅ Code Check output

[notice] A new release of pip is available: 26.0.1 -> 26.1
[notice] To update, run: pip install --upgrade pip
----------------------------------------
Checking: salesforce
----------------------------------------

📦 Installing dependencies...

🐍 Checking Python syntax...
   ✅ Syntax OK

📥 Checking imports...
   ✅ Imports OK

📄 Checking JSON files...
   ✅ JSON files OK

🔍 Linting with ruff...
   ✅ Lint OK

🎨 Checking formatting with ruff...
   ✅ Formatting OK

🔒 Scanning for security issues with bandit...
   ✅ Security OK

🛡️ Checking dependencies for vulnerabilities with pip-audit...
   ✅ Dependencies OK

🔗 Checking config-code sync...
   ✅ Config-code sync OK

🔄 Checking fetch patterns...
   ✅ Fetch patterns OK

========================================
✅ CODE CHECK PASSED
========================================
✅ Tests output

Integration    Tests  Coverage        Status
--------------------------------------------
salesforce     63/63       96%      ✅ Passed
--------------------------------------------
Total          63/63            ✅ All passed

✅ Tests passed: salesforce
✅ README Check output
========================================
✅ README CHECK PASSED
========================================
✅ Version Check output
✅ salesforce: 1.0.0 → 2.0.0 (major bump)

========================================
✅ VERSION CHECK PASSED
========================================

Comment thread shotstack/shotstack.py Fixed
@Shubhank-Jonnada Shubhank-Jonnada force-pushed the fix/salesforce-instance-url-fallback branch from b74cee6 to 78922ab Compare April 27, 2026 22:07
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b74cee610f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread shotstack/shotstack.py Outdated
Comment thread shotstack/shotstack.py Outdated
Comment thread shotstack/shotstack.py Outdated
Copy link
Copy Markdown
Member

@ProRedCat ProRedCat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of fixing this on the integration side, we should instead make it so that the instance url is stored in the metadata field which can then be accessed here

This way we don't have to do a request to fetch what the instance URL is. We have a few integrations that follow this pattern already (see Discord)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants