ml-connector
SAP S/4HANATwilio

SAP S/4HANA and Twilio integration

SAP S/4HANA runs your finance and procurement. Twilio sends notifications and alerts to mobile and email. Connecting the two lets you notify suppliers in real-time when purchase orders are approved or invoices are due, send payment confirmation codes to vendors, and trigger SMS alerts for exception handling in your procurement process without re-keying contact data.

How SAP S/4HANA works

SAP S/4HANA exposes finance and procurement records through OData V2 and OData V4 REST APIs at a tenant-specific base URL, including suppliers, customers, purchase orders, supplier invoices, GL accounts, cost centers, and journal entries. Authentication uses OAuth2 client credentials, with tokens typically valid for 12 hours that must be refreshed before expiry. The SAP admin creates a Communication System, User, and Arrangement before API access is available. SAP S/4HANA has no native webhooks for cloud public editions, so events are retrieved by polling with LastChangeDateTime filters or delta tokens. On-premise instances require an additional sap-client query parameter.

How Twilio works

Twilio exposes messaging, voice, and verification APIs through REST endpoints with regional variants and multiple service URLs depending on the feature: core API, messaging services, verify service, phone lookups, conversations, video, studio flows, and taskrouter. Authentication uses HTTP Basic Auth with either Account SID and Auth Token or an API Key SID and Secret; API keys can be restricted to fine-grained scopes. Twilio delivers incoming messages, message status callbacks, and verification status changes through webhooks, but webhook delivery is not guaranteed exactly-once so handlers must be idempotent. Request bodies use application/x-www-form-urlencoded format rather than JSON, and webhook signatures are validated with HMAC-SHA1.

What moves between them

Purchase orders, invoices, and payment records from SAP S/4HANA trigger outbound Twilio SMS and email messages to supplier and customer contact numbers and addresses stored in S/4HANA's business partner records. The flow is unidirectional: SAP S/4HANA to Twilio. Status callbacks from Twilio for message delivery (queued, sending, sent, delivered, failed, undelivered) are received as webhooks and stored in the audit log. Verification codes for outgoing payments can be sent via Twilio Verify service before processing sensitive transactions.

How ml-connector handles it

ml-connector caches the OAuth2 bearer token for S/4HANA and refreshes it before expiry to avoid failed calls mid-flow. Supplier and customer contact details are read from S/4HANA's A_BusinessPartner and A_Supplier entities on a schedule you define, then mapped to Twilio phone numbers and email addresses. When a purchase order is approved or an invoice is due, ml-connector sends an SMS or email through the appropriate Twilio API endpoint and registers a webhook to receive delivery status callbacks. Webhook signatures are validated using HMAC-SHA1 with the Twilio Auth Token. Since Twilio's request bodies are form-encoded rather than JSON, ml-connector parses and transforms the format before storage. Because webhook delivery is not guaranteed exactly-once, the audit log carries an idempotency key per message so duplicate callbacks do not create duplicate alert records. GL accounts and cost centers in S/4HANA are read-only, so ml-connector does not write financial records back to S/4HANA; it only reads and sends notifications.

A real-world example

A mid-sized procurement team at a global manufacturer uses SAP S/4HANA to manage thousands of supplier relationships and purchase orders across multiple plants and regions. Before the integration, the team sent email notifications manually or relied on generic ERP alerts that suppliers often missed because the messages came from noreply addresses with no context. With SAP S/4HANA and Twilio connected, when a purchase order is approved in S/4HANA, ml-connector automatically sends a personalized SMS to the supplier contact phone number stored in S/4HANA with the PO number, required delivery date, and amount. Invoices are matched to the original PO and a reminder email is sent 5 days before the due date. Suppliers receive timely, clear, and direct communication, order fulfillment accelerates, and the procurement team no longer spends time on follow-up calls.

What you can do

  • Send SMS notifications to suppliers when purchase orders are approved or shipments are received, using contact numbers from SAP S/4HANA business partner records.
  • Trigger email alerts to customers when invoices are issued or payments are received, with details from S/4HANA GL accounts and journal entries.
  • Generate and send verification codes via Twilio Verify before processing high-value or sensitive outgoing payments from S/4HANA.
  • Validate Twilio webhook signatures using HMAC-SHA1, parse form-encoded callbacks, and store delivery status (sent, delivered, failed) in a full audit trail.
  • Refresh OAuth2 tokens for S/4HANA automatically before expiry, handle unidirectional flow from ERP to communications, and ensure idempotent processing of duplicate webhook callbacks.

Questions

Does ml-connector write data back into SAP S/4HANA from Twilio?
No. This is a unidirectional flow from SAP S/4HANA to Twilio. ml-connector reads supplier and customer contact data, purchase orders, invoices, and payment records from S/4HANA and sends SMS and email messages through Twilio, but it does not write financial records, business partner data, or GL accounts back to S/4HANA. GL accounts and cost centers in S/4HANA are read-only on the API.
How does ml-connector handle Twilio's form-encoded request format and webhook callbacks?
Twilio sends request bodies in application/x-www-form-urlencoded format, not JSON. ml-connector parses the form-encoded webhook payloads to extract message SIDs, delivery status (sent, delivered, failed), and timestamp. Webhook signatures are validated using HMAC-SHA1 with the Twilio Auth Token to ensure the request came from Twilio. Since Twilio webhook delivery is not guaranteed exactly-once, ml-connector includes an idempotency key in the audit log so duplicate callbacks do not create duplicate records.
What happens if the OAuth2 token for SAP S/4HANA expires during a send?
ml-connector caches the OAuth2 bearer token and refreshes it before expiry, typically every 11 hours when tokens are valid for 12 hours. The SAP admin must configure the Communication Arrangement in S/4HANA to provide the token endpoint URL and client credentials. If a token expires mid-request, Twilio returns a 401 error and ml-connector retries the request with a fresh token on the next attempt, ensuring no messages are silently dropped.

Related integrations

Connect SAP S/4HANA and Twilio

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

Get started