# SAP Business One Service Layer Sales Order Request Generator

> Source: https://netray.co/tools/sap-b1-service-layer-sales-order-json-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in server, company database, customer and line details to get ready-to-test Login and sales order POST requests for the Service Layer REST API.

## Category

developer

## Erp

SAP Business One

## Audience

- SAP Business One developer
- Integration engineer
- Consultant

## Tool

**Kind:** template

**Output:** code

**Language:** http

**Fields:**

#### Service Layer host and port

**Key:** host

**Type:** text

**Default:** b1server.example.com:50000

#### Company database

**Key:** company_db

**Type:** text

**Default:** SBODEMOUS

#### B1 user name

**Key:** user

**Type:** text

**Default:** api_user

#### Customer code (CardCode)

**Key:** card_code

**Type:** text

**Default:** C20000

#### Delivery date (DocDueDate)

**Key:** due_date

**Type:** date

**Default:** 2026-11-15

#### Customer PO number (NumAtCard)

**Key:** ref

**Type:** text

**Default:** PO-77415

#### Item code, line 1

**Key:** item1

**Type:** text

**Default:** A00001

#### Quantity, line 1

**Key:** qty1

**Type:** number

**Default:** 10

#### Unit price, line 1

**Key:** price1

**Type:** number

**Default:** 125.50

#### Item code, line 2

**Key:** item2

**Type:** text

**Default:** A00002

#### Quantity, line 2

**Key:** qty2

**Type:** number

**Default:** 4

**Blocks:**

#### 1. Log in

**Body:** POST https://{{host}}/b1s/v1/Login
Content-Type: application/json

{
  "CompanyDB": "{{company_db}}",
  "UserName": "{{user}}",
  "Password": "<your password>"
}

#### 2. Create the sales order

**Body:** POST https://{{host}}/b1s/v1/Orders
Content-Type: application/json
Cookie: B1SESSION=<session id from login response>

{
  "CardCode": "{{card_code}}",
  "DocDueDate": "{{due_date}}",
  "NumAtCard": "{{ref}}",
  "DocumentLines": [
    {
      "ItemCode": "{{item1}}",
      "Quantity": {{qty1}},
      "UnitPrice": {{price1}}
    },
    {
      "ItemCode": "{{item2}}",
      "Quantity": {{qty2}}
    }
  ]
}

#### 3. Read it back

**Body:** GET https://{{host}}/b1s/v1/Orders?$filter=NumAtCard eq '{{ref}}'&$select=DocEntry,DocNum,CardCode,DocTotal
Cookie: B1SESSION=<session id>

**Notes:** Verify the base path, port and entity names for your version, since Service Layer paths and supported fields differ between releases. Line two omits UnitPrice so the system applies the price list. Never commit passwords. Log out with POST /b1s/v1/Logout when done and test in a non-production company first.

## Content

**Intro:** The SAP Business One Service Layer exposes business objects such as sales orders as REST resources. Getting the first login and order request right is the usual hurdle for integration developers, so this tool generates both from your values.

**Sections:**

#### How to use it

**Body:** Enter your Service Layer host and port, company database, user and the business data for the order. Copy the generated Login request, send it with any REST client, and take the session ID from the response. Then send the Orders request with that session cookie. The third block reads the order back by customer PO number.

#### How the API is shaped

**Body:** Login returns a session ID that you send as the B1SESSION cookie. Documents are created by POST to their collection, such as Orders, with header fields at the top level and an array of DocumentLines. Field names follow the business object schema, for example CardCode, DocDueDate, ItemCode and Quantity. Queries use OData options like filter and select.

**Bullets:**

- Sessions time out, so handle re-login on a 401
- Omitting UnitPrice lets the price list apply
- Use NumAtCard to store the customer's PO reference

#### Testing and safety

**Body:** Create the order in a test company first, then check it in the client. Use a dedicated API user with limited authorisations. Keep passwords in a secret store, not in scripts. Record the returned DocEntry and DocNum in your integration log so you can trace each order back to its source.

#### Common mistakes

**Body:** Forgetting the session cookie, sending numbers as strings, using a date format the server rejects, passing an inactive item or customer code, and posting duplicates after a timeout. Make integrations idempotent by checking NumAtCard before creating the order.

**Cta:** If you want an integration between your e-commerce, EDI or shop floor and SAP Business One reviewed or built, Netray can help. The generator is free on its own.

**Faq:**

#### What is the Service Layer?

**Answer:** It is the REST and OData based API of SAP Business One for HANA and SQL versions that lets external applications read and write business objects over HTTPS. Availability and details depend on your version.

#### Why does my POST return an authentication error?

**Answer:** Usually the session cookie is missing or expired. Log in again and send the B1SESSION value on every request. Also check the user has authorisation for the object.

#### How do I avoid duplicate orders?

**Answer:** Query by a unique reference such as NumAtCard before you post, and store the returned DocEntry. If a request times out, check for the order before retrying.

#### Can I create other documents the same way?

**Answer:** Yes. Deliveries, invoices, purchase orders and business partners follow the same pattern with their own collections and field names. Check the entity reference for your version.

## Search terms

sap business one service layer, sap b1 service layer create sales order, service layer post orders json, sap b1 rest api example, b1s/v1 login, sap business one integration, service layer documentlines, sap b1 api sales order

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
