ml-connector
SAP S/4HANABasware

SAP S/4HANA and Basware integration

SAP S/4HANA runs finance, procurement, and the supplier ledger. Basware runs AP automation, where invoices are received, coded, matched, and approved. Connecting the two pushes SAP vendor master, GL accounts, and cost centers into Basware so coders work from valid values, and posts each coded and approved Basware invoice back into SAP as a supplier invoice. ml-connector handles the different APIs on each side, fetches the SAP token that every write requires, and moves the data on the cadence you set. Because Basware has no outbound payment engine, payment status flows back into Basware from SAP rather than the reverse.

How SAP S/4HANA works

SAP S/4HANA Cloud exposes suppliers and business partners, supplier invoices, purchase orders, GL accounts, cost centers, and journal entries through OData V2 and V4 services on a tenant-specific URL such as https://my123456-api.s4hana.ondemand.com. System-to-system access uses OAuth 2.0 client credentials and requires an SAP admin to set up a Communication Arrangement first, with each service tied to a communication scenario like SAP_COM_0057 for supplier invoices. Every write operation needs an X-CSRF-Token fetched in a prior GET, and SAP rejects duplicate supplier invoices on the same reference, company code, and fiscal year. SAP Cloud has no native webhook to external URLs, so records are read by polling on LastChangeDateTime, with SAP Event Mesh available only when the customer already licenses SAP BTP.

How Basware works

Basware exposes invoices, purchase orders, vendors, GL accounts, and cost dimensions through its REST P2P API under a /v1/ path on a region-specific base URL such as https://api.basware.com or https://api.us.basware.com. It authenticates with OAuth 2.0 client credentials, where the client id and secret are sent as Basic auth to request a bearer token that lasts up to 24 hours, and credentials are provisioned by a Basware consultant rather than self-served. Master data such as vendors, accounts, and dimensions is imported by POST, and coded invoices are read from accountingDocuments and acknowledged once transferred. Basware pushes approval and transfer events by webhook signed with HMAC-SHA256 in the X-BWAPI-Signature-256 header, paginates with a continuation token passed as a request header, and silently skips re-imported records that have not changed.

What moves between them

Master data flows from SAP S/4HANA into Basware. ml-connector reads vendors from the Business Partner service and GL accounts and cost centers from their OData services, then imports them into Basware so the coding panel offers only valid suppliers, accounts, and dimensions. Open purchase orders move the same direction to support matching. Coded and approved invoices flow back from Basware into SAP: ml-connector reads each accountingDocument when Basware signals it is ready and posts it as a supplier invoice against the matching company code, vendor, and GL accounts. Once SAP records the payment, ml-connector confirms it to Basware through the payment response endpoint, since Basware has no outbound payment engine of its own. Master data sync runs on a schedule, while invoice posting is triggered by Basware webhooks.

How ml-connector handles it

ml-connector stores both credential sets encrypted and bridges the two OAuth client-credential logins, caching the SAP bearer token under its roughly 12-hour life and the Basware bearer token under its configured expiry. The SAP token endpoint and tenant URL are taken per customer, and the Basware region selects its base URL. Master data sync paginates SAP with $top and the nextLink and imports into Basware in batches, mapping SAP supplier numbers, GL accounts, and cost centers to the Basware vendor, account, and dimension codes; because a Basware import overwrites manual edits, SAP is treated as the system of record for that data. On the return path, each Basware approval webhook is verified against the HMAC-SHA256 X-BWAPI-Signature-256 header before processing, then ml-connector fetches an SAP X-CSRF-Token and posts the supplier invoice; the colon-free job id and SAP's own duplicate check on reference, company code, and fiscal year prevent double posting if a webhook is redelivered. Basware paginates with a continuation token returned in the response header and passed back as a request header, and unchanged records are silently skipped on re-import. SAP 429 and 403 CSRF responses trigger token re-fetch and exponential backoff, and every record carries a full audit trail and can be replayed if a downstream call fails.

A real-world example

A mid-sized manufacturer with about 1,500 employees runs SAP S/4HANA Cloud for finance and procurement and uses Basware to receive and approve its supplier invoices across three legal entities. Before the integration, accounts payable exported approved invoices from Basware and re-keyed them into SAP, which delayed posting, introduced coding mistakes, and left vendor and cost center lists in Basware out of date whenever finance changed them in SAP. With SAP S/4HANA and Basware connected, vendor master, GL accounts, and cost centers sync into Basware on a schedule so coders always pick valid values, and each approved invoice posts into SAP as a supplier invoice within minutes of approval against the right company code. Posting is no longer manual, coding errors drop, and payment status flows back to Basware so AP can see which invoices have cleared.

What you can do

  • Push SAP S/4HANA vendor master, GL accounts, and cost centers into Basware so coders pick from valid values.
  • Post each coded and approved Basware invoice into SAP S/4HANA as a supplier invoice against the right company code and accounts.
  • Trigger invoice posting from Basware approval webhooks verified by HMAC-SHA256, with a scheduled poll as backup.
  • Fetch the SAP X-CSRF-Token for every write and rely on SAP duplicate detection plus a job id to prevent double posting.
  • Confirm payment status back into Basware after SAP records it, and keep a full audit trail with replay on every record.

Questions

Which direction does data move between SAP S/4HANA and Basware?
Master data moves from SAP S/4HANA into Basware: vendors, GL accounts, and cost centers are imported so the coding panel offers valid values. Coded and approved invoices move the other way, posting into SAP as supplier invoices against the right company code and accounts. After SAP records a payment, ml-connector confirms it back to Basware, since Basware has no outbound payment engine.
How does the integration post invoices into SAP S/4HANA safely?
Every SAP write requires an X-CSRF-Token fetched in a prior request, so ml-connector fetches and reuses it and re-fetches on a 403. It posts each Basware invoice once its approval webhook is verified by HMAC-SHA256. SAP also rejects duplicate supplier invoices on the same reference, company code, and fiscal year, which combined with a per-invoice job id stops double posting if a webhook is redelivered.
Does SAP S/4HANA push invoices, or does ml-connector poll for them?
SAP Cloud has no native webhook to external URLs, so ml-connector polls SAP master data on a schedule using filters on LastChangeDateTime. The invoice path is event-driven from the Basware side instead, where approval webhooks trigger the post into SAP. SAP Event Mesh is only used when the customer already licenses SAP BTP.

Related integrations

Connect SAP S/4HANA and Basware

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

Get started