> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# SAP S/4HANA Cloud

> Client-mode REST API connector for a curated S/4HANA Cloud OData slice: production orders, confirmations, goods movements, and maintenance notifications

Technical Preview

## Overview

A client-mode connector for a **curated manufacturing and plant-maintenance** slice of [SAP S/4HANA Cloud](https://api.sap.com/products/SAPS4HANACloud/apis/packages) OData APIs on the Business Accelerator Hub:

| Catalog connector event | OData service | Entity set |
| - | - | - |
| GET production orders by plant | `API_PRODUCTION_ORDER_2_SRV` | `A_ProductionOrder_2` |
| POST order confirmation (yield, scrap, time) | `API_PROD_ORDER_CONFIRMATION_2_SRV` | `ProdnOrdConf2` |
| POST goods movement | `API_MATERIAL_DOCUMENT_SRV` | `A_MaterialDocumentHeader` |
| POST maintenance notification from alarm | `API_MAINTNOTIFICATION` | `MaintenanceNotification` |

`BASE_ADDRESS` is the tenant host root (`https://{tenant}-api.s4hana.cloud.sap`). Endpoints carry `/sap/opu/odata/sap/...`. Topics use `erp/sap-s4hana-cloud/<object>/<verb>`.

> [!NOTE]
>
> S/4HANA Cloud OData requires a real tenant and either a communication-user (Basic) or OAuth 2.0 client-credentials Bearer token. Mutating calls need an `X-CSRF-Token` (fetch with `Fetch` first). This template has not been verified against a live tenant.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — SAP S/4HANA Cloud (curated Manufacturing / PM slice)
# Generated from curated OpenAPI; credentials are placeholders only.
# Docs: https://docs.coreflux.org/latest/lot-language/routes/rest-api-routes
# Auth: OAuth 2.0 client credentials (Bearer {value.json.access_token}) OR Basic
#       communication user (WITH USERNAME / WITH PASSWORD GET SECRET). Never commit secrets.
# BASE_ADDRESS: https://{tenant}-api.s4hana.cloud.sap — replace YOUR_TENANT.
# OData mutating calls need CSRF: run Fetchcsrf first (X-CSRF-Token: Fetch), then pass
#   {value.json.csrf_token} on POST events. Keep session cookies if the broker exposes them.
# Accelerator Hub refs:
#   API_PRODUCTION_ORDER_2_SRV · API_PROD_ORDER_CONFIRMATION_2_SRV
#   API_MATERIAL_DOCUMENT_SRV · API_MAINTNOTIFICATION

DEFINE ROUTE SapS4hanaCloudRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_TENANT-api.s4hana.cloud.sap"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
        # Auth option A (OAuth client credentials): obtain access_token upstream, pass as Bearer.
        # Auth option B (Basic communication user): uncomment and use Hub secrets:
        #   WITH USERNAME "YOUR_COMM_USER"
        #   WITH PASSWORD GET SECRET "SAP_S4_COMM_PASSWORD"
        # Prefer Hub secrets / GET SECRET — never commit real tokens or passwords.
    ADD EVENT Getproductionordersbyplant
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/production-order/get"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/production-order/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2?$filter=ProductionPlant eq '{value.json.plant}'&$format=json"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Getproductionorder
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/production-order/get-by-id"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/production-order/get-by-id/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2('{value.json.ManufacturingOrder}')?$format=json"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Fetchcsrf
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/csrf/fetch"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/csrf/fetch/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification?$top=1&$format=json"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "X-CSRF-Token" "Fetch"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Createproductionorderconfirmation
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/production-order-confirmation/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/production-order-confirmation/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/sap/opu/odata/sap/API_PROD_ORDER_CONFIRMATION_2_SRV/ProdnOrdConf2"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "X-CSRF-Token" "{value.json.csrf_token}"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Creatematerialdocument
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/material-document/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/material-document/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/sap/opu/odata/sap/API_MATERIAL_DOCUMENT_SRV/A_MaterialDocumentHeader"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "X-CSRF-Token" "{value.json.csrf_token}"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"
    ADD EVENT Createmaintenancenotification
        WITH SOURCE_TOPIC "erp/sap-s4hana-cloud/maintenance-notification/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-cloud/maintenance-notification/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "X-CSRF-Token" "{value.json.csrf_token}"
            ADD "Authorization" "Bearer {value.json.access_token}"
        WITH BODY "{payload}"

```

## Events

| Event | Method | Endpoint | Request topic | Response topic |
| - | - | - | - | - |
| Getproductionordersbyplant | GET | `/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2?$filter=ProductionPlant eq '{plant}'` | `erp/sap-s4hana-cloud/production-order/get` | `erp/sap-s4hana-cloud/production-order/get/response` |
| Getproductionorder | GET | `/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2('{ManufacturingOrder}')` | `erp/sap-s4hana-cloud/production-order/get-by-id` | `erp/sap-s4hana-cloud/production-order/get-by-id/response` |
| Fetchcsrf | GET | `/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification` | `erp/sap-s4hana-cloud/csrf/fetch` | `erp/sap-s4hana-cloud/csrf/fetch/response` |
| Createproductionorderconfirmation | POST | `/sap/opu/odata/sap/API_PROD_ORDER_CONFIRMATION_2_SRV/ProdnOrdConf2` | `erp/sap-s4hana-cloud/production-order-confirmation/create` | `erp/sap-s4hana-cloud/production-order-confirmation/create/response` |
| Creatematerialdocument | POST | `/sap/opu/odata/sap/API_MATERIAL_DOCUMENT_SRV/A_MaterialDocumentHeader` | `erp/sap-s4hana-cloud/material-document/create` | `erp/sap-s4hana-cloud/material-document/create/response` |
| Createmaintenancenotification | POST | `/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification` | `erp/sap-s4hana-cloud/maintenance-notification/create` | `erp/sap-s4hana-cloud/maintenance-notification/create/response` |

## Auth

OAuth Bearer (client credentials access token):

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
ADD "Authorization" "Bearer {value.json.access_token}"
```

Or Basic communication user on config (Hub secret):

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
WITH USERNAME "YOUR_COMM_USER"
WITH PASSWORD GET SECRET "SAP_S4_COMM_PASSWORD"
```

CSRF on POST:

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
ADD "X-CSRF-Token" "{value.json.csrf_token}"
```

**access\_token** `string` *required*

OAuth 2.0 access token from the S/4HANA Cloud / BTP token endpoint (client credentials). Prefer a Hub secret. Never commit the token.

**plant** `string` *required*

Production plant code for Getproductionordersbyplant (`ProductionPlant` OData filter).

**ManufacturingOrder** `string`

Production order key for Getproductionorder.

**csrf\_token** `string` *required*

Value from the `X-CSRF-Token` response header after Fetchcsrf. Required on all POST events.

High-level setup (no secrets in the template):

1. Create Communication Arrangements for the needed scenarios (e.g. production / confirmation, material document, maintenance `SAP_COM_0397`).
2. Create a communication user or OAuth client; obtain Basic credentials or an access token.
3. Set `BASE_ADDRESS` to `https://{tenant}-api.s4hana.cloud.sap`.
4. Fetch CSRF, then call GET/POST events with placeholders filled.

GET production orders by plant smoke payload:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{"access_token": "YOUR_S4_ACCESS_TOKEN", "plant": "1010"}
```

POST maintenance notification (connector body is `{payload}`; fetch CSRF first):

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_S4_ACCESS_TOKEN",
  "csrf_token": "YOUR_CSRF_TOKEN",
  "NotificationType": "Y1",
  "NotificationText": "Alarm from Coreflux edge",
  "TechnicalObject": "EQUIPMENT_ID",
  "TechObjIsEquipOrFuncnlLoc": "EAMS_EQUIP",
  "MaintPriority": "2",
  "MaintenanceObjectIsDown": true
}
```

## Try it

1. Replace `YOUR_TENANT` in `BASE_ADDRESS` and add the connector on a lab broker.
2. Publish token + plant JSON to `erp/sap-s4hana-cloud/production-order/get`.
3. Subscribe to `erp/sap-s4hana-cloud/production-order/get/response`.
4. For POSTs: call `erp/sap-s4hana-cloud/csrf/fetch` first, then publish with `csrf_token` and body fields.

> [!NOTE]
>
> Recorded factory probes without a tenant: Accelerator Hub overviews HTTP 200, Help Portal HTTP 200, sandbox OData unauthenticated HTTP 401, placeholder tenant host unreachable. Live tenant smoke is still required before status ready.

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps](/latest/lot-language/routes/rest-api-apps)
* [SAP Business Accelerator Hub — S/4HANA Cloud](https://api.sap.com/products/SAPS4HANACloud/apis/packages)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.