Connect Salesforce to n8n?
Connect Salesforce to n8n? You can connect Salesforce to n8n using OAuth2 and Docker by creating a Salesforce connected app, running n8n in Docker, and configuring OAuth2 credentials inside n8n. This guide gives simple steps, commands, and a quick test so you can start automating Salesforce with n8n workflows.
What You Need to Connect Salesforce to n8n
- A Salesforce account with permissions to create a connected app.
- A machine with Docker installed.
- n8n Docker image and persistent volume for credentials.
- A public or local URL for OAuth redirect (use ngrok for local testing).
Step 1: Create a Salesforce Connected App
Open Salesforce Setup and create a new Connected App. Set the OAuth callback URL to n8n’s OAuth callback. Add API and refresh token scopes.
Callback URL example:
http://localhost:5678/rest/oauth2-credential/callback
Scopes (recommended):
api refresh_token full
Step 2: Run n8n in Docker
Run n8n with a persistent data folder. If you are testing locally, set WEBHOOK_URL to the public or local address you used in the connected app.
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
-e N8N_HOST="localhost" \
-e N8N_PORT=5678 \
-e N8N_PROTOCOL="http" \
-e WEBHOOK_URL="http://localhost:5678" \
-e N8N_BASIC_AUTH_ACTIVE=true \
-e N8N_BASIC_AUTH_USER="admin" \
-e N8N_BASIC_AUTH_PASSWORD="strongpassword" \
n8nio/n8n:latest
If you need a public URL for OAuth, run ngrok and update WEBHOOK_URL and the connected app callback.
ngrok http 5678
# Copy the https://... URL and use it as the WEBHOOK_URL and callback URL.
Step 3: Configure OAuth2 Credential in n8n
Open n8n UI at http://localhost:5678 and create new credentials for Salesforce OAuth2. Use these values from your connected app.
Auth URL: https://login.salesforce.com/services/oauth2/authorize
Token URL: https://login.salesforce.com/services/oauth2/token
Client ID: YOUR_SALESFORCE_CLIENT_ID
Client Secret: YOUR_SALESFORCE_CLIENT_SECRET
Redirect URI: https://your-webhook-url/rest/oauth2-credential/callback
Scope: api refresh_token
Click connect and complete the OAuth flow. n8n will store the access and refresh tokens in its credential store.
Step 4: Test the Connection
Make a simple request with n8n to fetch Salesforce data or test the token endpoint with curl.
# Example: exchange an authorization code for a token (for manual testing)
curl -X POST https://login.salesforce.com/services/oauth2/token \
-d "grant_type=authorization_code" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "redirect_uri=https://your-webhook-url/rest/oauth2-credential/callback" \
-d "code=AUTHORIZATION_CODE"
Then create a simple n8n workflow using the Salesforce node to list accounts or query data. Run the workflow to verify authentication and API calls.
Update
If Salesforce rotates keys or you change the connected app, update the Client ID and Client Secret in n8n credentials. Reconnect via the OAuth flow if tokens are invalidated.
Security
- Use strong basic auth for n8n when exposed to the internet.
- Use HTTPS for WEBHOOK_URL in production.
- Limit Salesforce connected app scopes to only what you need.
- Rotate client secrets and store secrets securely.
Done
You now have Salesforce connected to n8n. Create workflows that use Salesforce triggers and actions to automate tasks. Monitor tokens and update credentials when needed.