ml-connector
SAP S/4HANAServiceNow

SAP S/4HANA and ServiceNow integration

SAP S/4HANA runs your procurement and finance. ServiceNow runs your accounts payable and service operations. Connecting the two keeps supplier records, purchase orders, and invoice GL postings aligned across both systems. New suppliers and POs created in SAP flow into ServiceNow's procurement module, and approved invoices in ServiceNow map back to SAP's GL accounts and cost centers without re-entry.

How SAP S/4HANA works

SAP S/4HANA exposes suppliers, purchase orders, supplier invoices, GL accounts, cost centers, and purchase requisitions through OData V2 and OData V4 REST APIs, secured with OAuth 2.0 client credentials assigned per Communication Arrangement. The cloud product runs at a tenant-specific URL and requires the admin to create a Communication System and User before API access is available. Tokens are short-lived (typically 12 hours) and must be cached and refreshed before expiry. SAP offers no native webhooks, so connectors must poll using filter=LastChangeDateTime or delta tokens. Event-driven sync is possible via SAP Event Mesh but requires SAP Business Technology Platform.

How ServiceNow works

ServiceNow exposes procurement, accounts payable, and source-to-pay operations through REST APIs at a customer-supplied subdomain, authenticated with OAuth 2.0 client credentials or basic auth. The Source-to-Pay suite is a licensed module add-on that includes staging tables for invoices, POs, and supplier records. Every operation requires module-level roles such as sn_apay.apo_user. ServiceNow supports no native outbound webhooks; the standard pattern is polling with a sysparm_query filter on sys_updated_on at an admin-configured schedule. OAuth tokens expire after 30 minutes by default.

What moves between them

The main flow runs from SAP into ServiceNow. Supplier master records, purchase order headers and line items, and purchase requisitions created in SAP are read via OData and written to ServiceNow's procurement staging tables on a daily or weekly schedule. The reverse flow reads approved invoices and cost allocations from ServiceNow's accounts payable module, maps each invoice to the matching SAP cost center and GL account, and posts them into SAP's journal entry API. Reference data such as suppliers and cost centers is synchronized in both directions so every invoice line references a valid GL account and cost center in SAP.

How ml-connector handles it

ml-connector stores the SAP OAuth credentials (client ID, client secret, and communication system URL) encrypted and refreshes the bearer token every 11 hours before expiry, caching the token across requests to minimize API calls. For ServiceNow, it stores the instance URL and OAuth credentials separately and manages the 30-minute token lifespan. Supplier records are fetched from SAP's A_Supplier and A_SupplierCompany OData entities and staged in ServiceNow's sn_s2p_supplier_inbound_staging table with a unique external ID so duplicates do not accumulate. Purchase orders flow from SAP A_PurchaseOrder and A_PurchaseOrderItem to ServiceNow proc_po and proc_po_item. Invoices are read from ServiceNow sn_apo_invoice, matched to the original PO and cost center, and posted to SAP's A_JournalEntry API with the correct GL account and cost center dimension. Cost center and GL account master data are queried once per sync cycle and cached to avoid N+1 lookups. All reads use OData filter=LastChangeDateTime to fetch only records modified since the last run, and all posts carry an idempotency key to prevent duplicate journal entries if a retry occurs. Every record is logged with timestamp, direction, and status.

A real-world example

A mid-sized manufacturing company runs SAP S/4HANA for procurement, inventory, and consolidated accounting across three plants. The accounts payable team uses ServiceNow for invoice receipt, approval routing, and GL coding. Before the integration, the procurement team exported new suppliers and POs from SAP each week and manually created them in ServiceNow, and the AP team exported approved invoices from ServiceNow, coded each line to the correct cost center, and re-entered them into SAP's journal entry module, a process that took 4 to 6 hours per week and introduced manual errors. With SAP and ServiceNow connected, suppliers and POs flow from SAP into ServiceNow automatically, approved invoices flow back to SAP with cost center and GL account coding already validated, and the manual re-entry step is eliminated. Accounts payable close now begins with invoices already posted to the general ledger, and the reconciliation step between the two systems is gone.

What you can do

  • Synchronize SAP suppliers, companies, and POs into ServiceNow procurement tables on a daily or weekly schedule.
  • Post ServiceNow approved invoices into SAP's general ledger, mapped to the correct GL accounts and cost centers.
  • Bridge SAP OAuth 2.0 and ServiceNow OAuth 2.0 authentication, managing token refresh and expiry for both systems.
  • Deduplicate suppliers and POs using external IDs so re-syncs do not create duplicate records.
  • Handle OData filtering on LastChangeDateTime to fetch only changed records, reducing API load and sync time.

Questions

Which direction does data flow between SAP S/4HANA and ServiceNow?
The main flow runs from SAP into ServiceNow. Suppliers, purchase orders, and purchase requisitions are synchronized from SAP into ServiceNow's procurement module on a schedule. Approved invoices flow from ServiceNow back to SAP, where ml-connector maps them to GL accounts and cost centers and posts them as journal entries. Reference data such as cost centers and GL accounts are kept in sync in both directions.
How does ml-connector handle SAP's short-lived OAuth tokens and ServiceNow's 30-minute token limit?
ml-connector stores both credential sets encrypted and refreshes them proactively before expiry. For SAP, tokens are cached and refreshed every 11 hours (before the typical 12-hour expiry). For ServiceNow, the token is refreshed every 25 minutes (before the default 30-minute expiry). Both systems' tokens are validated and re-requested on first-call 401 errors as a fallback.
What happens if a supplier or PO already exists in both systems?
ml-connector uses external IDs and a unique identifier from SAP to track which records have been synchronized. If a re-sync runs, the external ID prevents duplicate supplier or PO creation in ServiceNow. For invoices posted to SAP, an idempotency key ensures that a retry does not create duplicate journal entries if the first attempt partially succeeded.

Related integrations

Connect SAP S/4HANA and ServiceNow

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

Get started