ml-connector
SAP S/4HANAStedi

SAP S/4HANA and Stedi integration

SAP S/4HANA runs procurement and finance across your enterprise. Stedi translates JSON into X12 EDI messages and routes them to trading partners via SFTP, FTPS, or AS2. Connecting the two ensures purchase orders and invoices flow from SAP to your trading partners in standardized EDI format without manual export or reformatting. ml-connector polls SAP on a schedule, formats records into X12, and posts them to Stedi for delivery.

How SAP S/4HANA works

SAP S/4HANA exposes purchase orders, purchase order items, supplier invoices, invoice line items, suppliers, GL accounts, and cost centers through OData V2 and OData V4 REST APIs over HTTPS. Authentication uses OAuth 2.0 Client Credentials, with tokens typically valid for 12 hours and scoped per Communication Arrangement. The OData base URL is tenant-specific and structured as https://<tenant-id>-api.s4hana.ondemand.com/sap/opu/odata/sap/<SERVICE_NAME>/. SAP has no native webhooks for external connectors, so records are read by polling against the LastChangeDateTime field or using delta tokens for incremental fetches.

How Stedi works

Stedi is a REST-based EDI platform that accepts JSON payloads and translates them into X12 EDI messages for delivery to trading partners. All Stedi API calls authenticate via a static API Key in the Authorization header, which does not expire automatically and must be revoked manually via the portal. Outbound writes require an Idempotency-Key header for deduplication within a 24-hour window. Stedi routes EDI files to partners via SFTP, FTPS, or AS2 connections configured in the platform. Inbound EDI from partners is parsed into JSON and pushed via webhooks to your endpoint.

What moves between them

Purchase orders and supplier invoices flow from SAP S/4HANA to Stedi. ml-connector polls SAP's purchase order and supplier invoice APIs at a frequency you define, reads the GL account and cost center dimensions, and translates each purchase order into an X12 850 message and each supplier invoice into an X12 810 message. These JSON payloads are posted to Stedi for EDI encoding and delivery to the target partner. Response status from Stedi confirms successful receipt and queueing. No data flows back into SAP.

How ml-connector handles it

ml-connector stores the SAP tenant URL and OAuth credentials encrypted, and refreshes the bearer token before expiry to maintain continuity. It polls SAP using OData filter expressions on LastChangeDateTime to retrieve only changed records since the last run. For each purchase order or invoice, ml-connector maps SAP fields (PO number, line item detail, vendor, quantity, price, cost center, GL account) into X12 850 or 810 format. Before posting to Stedi, ml-connector generates a unique Idempotency-Key for each write so that retries do not create duplicate EDI messages. Stedi's API gateway returns 429 when rate-limited, triggering exponential backoff. ml-connector logs every transformation and delivery attempt so outbound EDI can be traced from SAP through Stedi to trading partner receipt.

A real-world example

A mid-sized industrial supplier runs SAP S/4HANA for purchasing and finance, and sends purchase orders and invoices to dozens of customers and vendors. Before the integration, the procurement team exported purchase orders from SAP weekly and manually formatted them into X12 EDI files, then uploaded them to Stedi's SFTP directory for delivery to trading partners. Errors in manual formatting sometimes caused rejections, requiring rework and late delivery. With SAP S/4HANA and Stedi connected, every purchase order and supplier invoice is automatically translated to X12 and queued for delivery as soon as it is entered in SAP, eliminating manual export steps and reducing EDI delivery latency from days to hours.

What you can do

  • Poll SAP S/4HANA for purchase orders and supplier invoices on a schedule you define, using OData delta filters to retrieve only changed records.
  • Translate SAP purchase order and invoice data into X12 850 (PO) and 810 (Invoice) messages with all line item detail, vendor, and GL account mappings.
  • Post X12 messages to Stedi for EDI encoding and delivery to trading partners via SFTP, FTPS, or AS2.
  • Manage SAP OAuth token refresh automatically and include Idempotency-Key headers on every Stedi write to prevent duplicate EDI messages.
  • Maintain a complete audit trail of every SAP record polled, transformation applied, and Stedi delivery status, with replay capability if a downstream step fails.

Questions

What direction does data flow between SAP S/4HANA and Stedi?
Data flows from SAP into Stedi. ml-connector polls purchase orders and supplier invoices from SAP S/4HANA, translates them to X12 EDI messages, and posts them to Stedi for delivery to trading partners. No data flows back into SAP. Stedi is the outbound EDI gateway; SAP is the source of truth for procurement documents.
How does ml-connector handle SAP's OAuth tokens and Stedi's Idempotency-Key requirement?
ml-connector stores the SAP tenant URL and OAuth credentials encrypted, and refreshes the bearer token before its 12-hour expiry window to maintain uninterrupted polling. For Stedi, ml-connector generates a unique Idempotency-Key for each outbound write, including it in the Authorization header on every request. This deduplicates retries within Stedi's 24-hour window so network failures do not create duplicate EDI messages.
How often does ml-connector poll SAP for new purchase orders and invoices?
Polling frequency is configurable based on your procurement cycle. ml-connector uses OData filter expressions on LastChangeDateTime to retrieve only records changed since the last run, so polling is efficient regardless of your data volume. Typical configurations poll every hour during business hours, or daily if invoices are batched overnight.

Related integrations

Connect SAP S/4HANA and Stedi

Free to use. Add your credentials, ping your real systems, and see if we fit.

Get started