Home » n8n» Connect SAP to n8n with Docker and OData

How to connect SAP to n8n?

You can connect SAP to n8n using SAP OData or RFC by running n8n in Docker and configuring an HTTP Request node for OData or a small Node.js RFC helper that posts to n8n webhooks. This guide shows the exact Docker commands, cURL tests, and a Node.js sample script so you can start automation quickly.

What You Need

  • Access to SAP Gateway OData endpoint or RFC user and host.
  • Docker and docker-compose installed on your machine.
  • n8n running (Docker).
  • Basic Node.js and npm for RFC examples.

How to connect SAP to n8n — Install n8n with Docker

Step 1: Create a docker-compose file and start n8n. This runs n8n with persistent data and basic auth.

version: '3'
services:
  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - 5678:5678
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=changeme
      - N8N_HOST=localhost
    volumes:
      - ./n8n-data:/home/node/.n8n

Step 2: Start the service.

docker-compose up -d
docker-compose logs -f n8n

Step 2: Connect to SAP OData from n8n

Use the HTTP Request node in n8n to call SAP OData. First test the SAP endpoint with cURL to confirm credentials and CSRF token flow.

1) Get CSRF token and cookies.

curl -i -u SAPUSER:PASS "https://sap.example.com/sap/opu/odata/sap/API_SERVICE/" -H "x-csrf-token: fetch"

2) Use the returned X-CSRF-Token and cookies in subsequent requests for POST/PUT.

3) In n8n, create a workflow with nodes:

  • Trigger (Webhook or Schedule)
  • HTTP Request node configured with Method, URL, Basic Auth, Header X-CSRF-Token and Cookie.
  • Function or Set node to map fields.

Example HTTP Request settings in n8n (fill fields in the UI):

Method: GET or POST
URL: https://sap.example.com/sap/opu/odata/sap/API_SERVICE/EntitySet
Authentication: Basic / OAuth (as your SAP setup)
Headers: { "x-csrf-token": "{{ $json["csrfToken"] }}", "Content-Type": "application/json" }

Step 3: Connect to SAP via RFC using Node.js

When RFC is required, run a small Node.js helper that uses node-rfc to call SAP and then posts results to an n8n webhook. This avoids complex native code inside n8n container.

Install dependencies and run a script.

mkdir sap-rfc-helper && cd sap-rfc-helper
npm init -y
npm install node-rfc axios

Create a script called rfc-to-n8n.js with this content:

const { Client } = require('node-rfc');
const axios = require('axios');

const connParams = {
  user: 'RFCUSER',
  passwd: 'RFCPASS',
  ashost: 'sap.example.com',
  sysnr: '00',
  client: '100',
  lang: 'EN'
};

async function run() {
  const client = new Client(connParams);
  await client.open();
  const result = await client.call('STFC_CONNECTION', { REQUTEXT: 'Hello SAP' });
  await axios.post('http://localhost:5678/webhook-test-path', result);
  await client.close();
}

run().catch(err => { console.error(err); process.exit(1); });

Run the script:

node rfc-to-n8n.js

In n8n, create a Webhook node to receive the posted RFC result and continue the workflow.


Update

To update n8n use docker-compose to pull the latest image and restart. Back up your data volume first.

docker-compose pull n8n
docker-compose up -d

Security

  • Use HTTPS for all SAP and n8n endpoints.
  • Do not store plain passwords in code. Use environment variables or secrets.
  • Limit SAP user permissions to only required RFCs or OData calls.
  • Enable n8n basic auth or OAuth and protect webhooks with keys.
  • Rotate credentials and monitor logs for failed attempts.

Done

You now have a working plan to connect SAP to n8n using OData or RFC. Test with simple reads first, then add transforms and automation steps. Keep credentials secure and update containers regularly.

Neil
Written by Neil

Neil is a true n8n geek who lives and breathes workflow automation. He dives deep into nodes, triggers, webhooks, custom logic, and self-hosting setups, sharing everything he learns about n8n on AutomationCompare.com. As part of a broader team of automation specialists, Neil focuses purely on mastering n8n and helping others unlock its full potential.

Keep Reading

Scroll to Top