> ## 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 Business One Service Layer

> Client-mode REST API connector for a curated SAP Business One Service Layer OData v4 slice: Items and warehouse stock, BusinessPartners, and InventoryGenEntries (receipt from production)

Technical Preview

## Overview

A client-mode connector for a **curated inventory and master-data** slice of [SAP Business One Service Layer](https://help.sap.com/doc/056f69366b5345a386bb8149f1700c19/10.0/en-US/Service%20Layer%20API%20Reference.html) OData v4 (`/b1s/v2`):

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| GET Items and warehouse stock | `Items`, `Items('{ItemCode}')` + `$expand=ItemWarehouseInfoCollection` | QuantityOnStock + per-warehouse collection |
| POST ProductionOrders receipt | `InventoryGenEntries` | Receipt from production: `DocumentLines.BaseType = 202` |
| GET BusinessPartners | `BusinessPartners` | Customers / vendors |
| Session | `Login`, `Logout` | `B1SESSION` (+ `ROUTEID`) cookie |

`BASE_ADDRESS` is the Service Layer root (`https://{host}:50000/b1s/v2`). Topics use `erp/sap-b1/<object>/<verb>`.

> [!NOTE]
>
> Service Layer requires a real company database and a session from `POST /Login`. This template has not been verified against a live tenant. Prefer Hub secrets for CompanyDB / UserName / Password.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — SAP Business One Service Layer (curated Items / stock / BP / receipt slice)
# Auth: Session login POST /Login → SessionId / Set-Cookie B1SESSION (+ ROUTEID).
# BASE_ADDRESS: https://YOUR_HOST:50000/b1s/v2

DEFINE ROUTE SapB1RestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_HOST:50000/b1s/v2"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Login
        WITH SOURCE_TOPIC "erp/sap-b1/session/login"
        WITH DESTINATION_TOPIC "erp/sap-b1/session/login/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/Login"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{payload}"
    ADD EVENT Logout
        WITH SOURCE_TOPIC "erp/sap-b1/session/logout"
        WITH DESTINATION_TOPIC "erp/sap-b1/session/logout/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/Logout"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
    ADD EVENT Getitems
        WITH SOURCE_TOPIC "erp/sap-b1/items/get"
        WITH DESTINATION_TOPIC "erp/sap-b1/items/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/Items?$select=ItemCode,ItemName,QuantityOnStock&$top={value.json.top}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
    ADD EVENT Getitemwarehousestock
        WITH SOURCE_TOPIC "erp/sap-b1/items/warehouse-stock/get"
        WITH DESTINATION_TOPIC "erp/sap-b1/items/warehouse-stock/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/Items('{value.json.ItemCode}')?$select=ItemCode,ItemName,QuantityOnStock&$expand=ItemWarehouseInfoCollection"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
    ADD EVENT Getbusinesspartners
        WITH SOURCE_TOPIC "erp/sap-b1/business-partners/get"
        WITH DESTINATION_TOPIC "erp/sap-b1/business-partners/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/BusinessPartners?$select=CardCode,CardName,CardType&$top={value.json.top}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
    ADD EVENT Createinventorygenentry
        WITH SOURCE_TOPIC "erp/sap-b1/inventory-gen-entry/create"
        WITH DESTINATION_TOPIC "erp/sap-b1/inventory-gen-entry/create/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/InventoryGenEntries"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
        WITH BODY "{payload}"

```

## Events

| Event | Method | Endpoint | Request topic | Response topic |
| - | - | - | - | - |
| Login | POST | `/Login` | `erp/sap-b1/session/login` | `erp/sap-b1/session/login/response` |
| Logout | GET | `/Logout` | `erp/sap-b1/session/logout` | `erp/sap-b1/session/logout/response` |
| Getitems | GET | `/Items` | `erp/sap-b1/items/get` | `erp/sap-b1/items/get/response` |
| Getitemwarehousestock | GET | `/Items('{ItemCode}')` + expand | `erp/sap-b1/items/warehouse-stock/get` | `erp/sap-b1/items/warehouse-stock/get/response` |
| Getbusinesspartners | GET | `/BusinessPartners` | `erp/sap-b1/business-partners/get` | `erp/sap-b1/business-partners/get/response` |
| Createinventorygenentry | POST | `/InventoryGenEntries` | `erp/sap-b1/inventory-gen-entry/create` | `erp/sap-b1/inventory-gen-entry/create/response` |

## Auth

Session login (required before data calls):

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{"CompanyDB": "YOUR_COMPANY_DB", "UserName": "YOUR_B1_USER", "Password": "YOUR_B1_PASSWORD"}
```

Cookie on later events:

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
ADD "Cookie" "B1SESSION={value.json.B1SESSION}; ROUTEID={value.json.ROUTEID}"
```

**CompanyDB** `string` *required*

Company database name for Login. Prefer a Hub secret. Never commit the password or live DB name into git.

**UserName** `string` *required*

SAP Business One user for Login.

**Password** `string` *required*

Password for Login. Prefer Hub `GET SECRET`. Never commit.

**B1SESSION** `string` *required*

Session id from Login response (`SessionId` / `B1SESSION` cookie). Required on all events after Login.

**ROUTEID** `string` *required*

Load-balancer cookie from Set-Cookie (often `.node1`). Use the value your Service Layer returns.

**ItemCode** `string`

Item key for Getitemwarehousestock.

**top** `integer`

OData `$top` for list GETs (Items / BusinessPartners).

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

1. Point `BASE_ADDRESS` at `https://{host}:50000/b1s/v2` (TLS; trust the SL certificate in the lab).
2. Login with CompanyDB / UserName / Password (Hub secrets).
3. Copy `SessionId` → `B1SESSION` and `ROUTEID` into subsequent MQTT payloads.
4. Call GET Items / BusinessPartners; for receipt from production POST InventoryGenEntries with `BaseType: 202`.
5. Logout.

Login smoke payload:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{"CompanyDB": "YOUR_COMPANY_DB", "UserName": "YOUR_B1_USER", "Password": "YOUR_B1_PASSWORD"}
```

GET Items (after login):

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{"B1SESSION": "YOUR_SESSION_ID", "ROUTEID": ".node1", "top": "10"}
```

POST receipt from production (connector body is `{payload}` — include Cookie fields in the same JSON envelope your broker expects, or set Cookie via header placeholders):

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "B1SESSION": "YOUR_SESSION_ID",
  "ROUTEID": ".node1",
  "DocDate": "2026-10-03",
  "Comments": "Receipt from production via Coreflux",
  "DocumentLines": [
    {
      "BaseType": 202,
      "BaseEntry": 1,
      "BaseLine": 0,
      "Quantity": 10,
      "WarehouseCode": "01"
    }
  ]
}
```

## Try it

1. Replace `YOUR_HOST` in `BASE_ADDRESS` and add the connector on a lab broker.
2. Publish login JSON to `erp/sap-b1/session/login`.
3. Subscribe to `erp/sap-b1/session/login/response`, then GET Items or BusinessPartners with `B1SESSION` / `ROUTEID`.
4. Optionally POST InventoryGenEntries for a known production order (`BaseType` 202).
5. Logout.

> [!NOTE]
>
> Recorded factory probes without a tenant: Help Portal / Service Layer API Reference HTTP 200, learning.sap login topic HTTP 200, placeholder host unreachable. Live CompanyDB session 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)
* [Service Layer API Reference](https://help.sap.com/doc/056f69366b5345a386bb8149f1700c19/10.0/en-US/Service%20Layer%20API%20Reference.html)
* [Working with SAP Business One Service Layer (PDF)](https://help.sap.com/doc/fc2f5477516c404c8bf9ad1315a17238/10.0/en-US/Working_with_SAP_Business_One_Service_Layer.pdf)


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