> ## 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 on-premise / ECC (Gateway)

> Client-mode REST API connector for SAP Gateway OData: production orders, confirmations, goods movements, maintenance notifications, work centers, and PM orders

Technical Preview

## Overview

A client-mode connector for a **curated manufacturing and plant-maintenance** slice of [SAP S/4HANA on-premise / ECC](https://api.sap.com/products/SAPS4HANA/apis/all) OData APIs exposed through [SAP Gateway](https://help.sap.com/docs/SAP_GATEWAY):

| 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` |
| GET work centers | `API_WORK_CENTERS` | `A_WorkCenters` |
| GET PM orders | `API_MAINTENANCEORDER` | `MaintenanceOrder` |

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

> [!NOTE]
>
> Service naming: Hub/SDK use `API_WORK_CENTERS` (not `API_WORK_CENTER_SRV`) and `API_MAINTENANCEORDER` (not `API_MAINTENANCEORDER_2_SRV`). Activate services in `/IWFND/MAINT_SERVICE` and confirm entity sets with `$metadata` on your host. Older ECC may expose classic PP/PM Gateway names — adjust after metadata check. Mutating OData calls need `X-CSRF-Token`. This template has not been verified against a live Gateway host.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — SAP S/4HANA on-premise / ECC (SAP Gateway)
# Generated from curated OpenAPI; credentials are placeholders only.
# Docs: https://docs.coreflux.org/latest/lot-language/routes/rest-api-routes
# Auth: Basic (WITH USERNAME / WITH PASSWORD GET SECRET "SAP_S4_ONPREM_PASSWORD") OR
#       OAuth 2.0 / SAML bearer (Bearer {value.json.access_token}). X.509 at TLS layer.
# BASE_ADDRESS: https://YOUR_HOST:YOUR_PORT — Gateway root; endpoints keep /sap/opu/odata/sap/...
# OData mutating calls need CSRF: run Fetchcsrf first (X-CSRF-Token: Fetch), then pass
#   {value.json.csrf_token} on POST events.

DEFINE ROUTE SapS4hanaOnpremRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_HOST:YOUR_PORT"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
        # Auth option A (OAuth / SAML bearer): obtain access_token upstream, pass as Bearer on events.
        # Auth option B (Basic Gateway user): uncomment and use Hub secrets:
        #   WITH USERNAME "YOUR_GATEWAY_USER"
        #   WITH PASSWORD GET SECRET "SAP_S4_ONPREM_PASSWORD"
        # Prefer Hub secrets / GET SECRET — never commit real tokens or passwords.
        # Auth option C (X.509): configure client cert at TLS / broker level (not in LoT headers).
    ADD EVENT Getproductionordersbyplant
        WITH SOURCE_TOPIC "erp/sap-s4hana-onprem/production-order/get"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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-onprem/production-order/get-by-id"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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 Getworkcenters
        WITH SOURCE_TOPIC "erp/sap-s4hana-onprem/work-center/get"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/work-center/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/sap/opu/odata/sap/API_WORK_CENTERS/A_WorkCenters?$filter=Plant eq '{value.json.plant}'&$format=json"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Getpmorders
        WITH SOURCE_TOPIC "erp/sap-s4hana-onprem/pm-order/get"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/pm-order/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/sap/opu/odata/sap/API_MAINTENANCEORDER/MaintenanceOrder?$filter=MaintenancePlanningPlant eq '{value.json.plant}'&$format=json"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.access_token}"
    ADD EVENT Fetchcsrf
        WITH SOURCE_TOPIC "erp/sap-s4hana-onprem/csrf/fetch"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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-onprem/production-order-confirmation/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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-onprem/material-document/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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-onprem/maintenance-notification/create"
        WITH DESTINATION_TOPIC "erp/sap-s4hana-onprem/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-onprem/production-order/get` | `erp/sap-s4hana-onprem/production-order/get/response` |
| Getproductionorder | GET | `/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2('{ManufacturingOrder}')` | `erp/sap-s4hana-onprem/production-order/get-by-id` | `erp/sap-s4hana-onprem/production-order/get-by-id/response` |
| Getworkcenters | GET | `/sap/opu/odata/sap/API_WORK_CENTERS/A_WorkCenters?$filter=Plant eq '{plant}'` | `erp/sap-s4hana-onprem/work-center/get` | `erp/sap-s4hana-onprem/work-center/get/response` |
| Getpmorders | GET | `/sap/opu/odata/sap/API_MAINTENANCEORDER/MaintenanceOrder?$filter=MaintenancePlanningPlant eq '{plant}'` | `erp/sap-s4hana-onprem/pm-order/get` | `erp/sap-s4hana-onprem/pm-order/get/response` |
| Fetchcsrf | GET | `/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification` | `erp/sap-s4hana-onprem/csrf/fetch` | `erp/sap-s4hana-onprem/csrf/fetch/response` |
| Createproductionorderconfirmation | POST | `/sap/opu/odata/sap/API_PROD_ORDER_CONFIRMATION_2_SRV/ProdnOrdConf2` | `erp/sap-s4hana-onprem/production-order-confirmation/create` | `erp/sap-s4hana-onprem/production-order-confirmation/create/response` |
| Creatematerialdocument | POST | `/sap/opu/odata/sap/API_MATERIAL_DOCUMENT_SRV/A_MaterialDocumentHeader` | `erp/sap-s4hana-onprem/material-document/create` | `erp/sap-s4hana-onprem/material-document/create/response` |
| Createmaintenancenotification | POST | `/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification` | `erp/sap-s4hana-onprem/maintenance-notification/create` | `erp/sap-s4hana-onprem/maintenance-notification/create/response` |

## Auth

OAuth / SAML Bearer access token:

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

Or Basic Gateway user on config (Hub secret):

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
WITH USERNAME "YOUR_GATEWAY_USER"
WITH PASSWORD GET SECRET "SAP_S4_ONPREM_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`

OAuth 2.0 / SAML bearer access token for Gateway. Prefer a Hub secret. Never commit the token. Omit when using Basic on `REST_API_CONFIG`.

**plant** `string` *required*

Plant code for Getproductionordersbyplant, Getworkcenters, and Getpmorders filters.

**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. Activate the OData services in `/IWFND/MAINT_SERVICE` (and confirm with Gateway Client `/IWFND/GW_CLIENT`).
2. Create a Gateway user (Basic), OAuth/SAML bearer client, or X.509 client cert.
3. Set `BASE_ADDRESS` to `https://{host}:{port}`.
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_GATEWAY_ACCESS_TOKEN", "plant": "1010"}
```

GET work centers / PM orders use the same shape (`plant`).

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

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "access_token": "YOUR_GATEWAY_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_HOST` / `YOUR_PORT` in `BASE_ADDRESS` and add the connector on a lab broker.
2. Publish token + plant JSON to `erp/sap-s4hana-onprem/production-order/get` (and optionally `work-center/get` / `pm-order/get`).
3. Subscribe to the matching `/response` topics.
4. For POSTs: call `erp/sap-s4hana-onprem/csrf/fetch` first, then publish with `csrf_token` and body fields.

> [!NOTE]
>
> Recorded factory probes without a Gateway host: Accelerator Hub product/overview pages HTTP 200, SAP Gateway Help Portal HTTP 200, placeholder host unreachable. Live Gateway 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 S/4HANA Cloud](/latest/lot-language/routes/rest-api-apps/sap-s4hana-cloud)
* [SAP Gateway Help](https://help.sap.com/docs/SAP_GATEWAY)
* [SAP Business Accelerator Hub — S/4HANA](https://api.sap.com/products/SAPS4HANA/apis/all)


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