4WS Suite
Home
API Reference
  • Data mangement API
  • Documents API
Home
API Reference
  • Data mangement API
  • Documents API
Fourwayshop
  1. Use cases
  • Four Way Shop API
  • Before start develop
  • Why we use Resource-oriented design
  • Technical Prerequisites
  • Concepts
    • Date Handling
    • Managing Languages
    • Handling Field Updates and Null Values in Service Requests
    • ISO Code
    • Vat rates
    • Product structure
    • Product Images
    • Product dimensions
    • Product pricing
    • Dimension group vs Dimension grouping
    • Subjects overview
    • Documents structure
  • Best Practices
    • Best Practices for Error Handling in External System
    • How Testing callback response
    • Best Practices for delopers
  • Data management
    • Authentication
    • Rate Limits
    • Paginated Responses
    • Getting Started
    • API Changelog
    • Use cases
      • Cataloging a Dimension
      • Creating a New Product
      • Retriving a product details
      • Defining Product Pricing
      • Updating External System Product Catalog
      • Activate product variants and add barcodes to SKUs
      • Move a Barcode from One Product to Another
    • API
      • Login
        • login
      • Product
        • Brand
          • Get All Brands
          • Get A Brand
          • Insert brand
          • Update brand
        • Season
          • Get All Seasons
          • Get A Season
          • Insert season
          • Update season
        • Attribute
          • Get All Attribute Types
          • Get Attribute Type
          • Get Attribute
          • Insert attribute
          • Update attribute
        • Hierarchy
          • Insert hierarchy
          • Update hierarchy
        • Dimension groups
          • Insert dimension group
          • Update dimension group
        • Dimension
          • Insert dimension
          • Update dimension
          • Delete dimension
        • Product
          • Get products
          • Get product
          • Get product grouping
          • Get SKU's barcodes
          • Get product stock
          • Insert product
          • Update product
        • Activate dimensions on products
          • Insert active dimensions
          • Delete active dimensions
        • Barcode
          • Get SKU from barcode
          • Generate missing barcodes
          • Generate missing barcode for SKU
          • Insert barcode
          • Delete barcode
        • Prices
          • Get product prices
        • Price dimension groupings
          • Get Dimension Price Grouping
          • Get All Dimension Price Grouping
          • Insert dimension grouping
          • Update dimension grouping
          • Delete dimension grouping
        • Assortment
          • insert product assortment
          • delete product assortment
        • Image
          • Get images
          • Add image
          • Replace image
          • Delete image
        • Supplier
          • Get Item suppliers
          • Insert item supplier
          • Delete item supplier
          • Update item supplier
        • Custom category
          • Get Custom code
          • Insert Custom code
          • Update Custom code
        • Vat
          • Vat types
            • Get VAT type
            • Get VAT types
          • VATs
            • Get VATs
            • Get VATs by type
            • Get VAT
          • Vat rates
            • Get VAT rates
            • Get single VAT rates
        • Stock
          • Insert stock
          • Get stock
      • Price lists
        • Get price lists
        • Get price lists by type
        • Get price list
        • Get prices from price list
        • Get entities from price lists
        • Insert Price List
        • Insert Product Price
        • Insert Entity On Price Lists
        • Update price list
        • Delete all product prices
        • Delete single product price
        • Delete entity from a price lists
      • Supplier
        • Supplier contacts
        • Supplier addresses
        • Get Suppliers
        • Get A Specific Supplier
        • Insert supplier
        • Update supplier
      • Entities
        • Get entities
        • Get entity
        • Insert entity
        • Update entity
      • Miscellaneous
        • Get requests rate limits
      • Catalog
        • Get Catalogs details
        • Get Catalog details by Code
        • Get products by Catalog Code
      • Export
        • Get bulk CSV Export
  • Documents
    • Authentication
    • Paginated responses
    • Managing API Callbacks
    • Document notifications
    • Customer promo data notifications
    • Use cases
      • Updating External System Stock
      • E-commerce Recipt Processing
      • E-commerce Return Receipt Processing
      • E-commerce Order sale Processing
      • E-commerce Return Order Processing
      • E-commerce Order Handling and Internal Stock Transfer
      • E-commerce & Gift Card
      • Creating a free entry
      • Retrieving a Document by Identifier
      • Cart Validation Service
      • Sale and Shipping costs
      • Handling Line Item Discounts
      • Managing Price Forcing in Cart Items
      • Purchase Order Registration
      • Supplier Goods Entry From Purchase Order
      • Update an Orchestrated Order
      • New Orchestrated Return Orders
    • API
      • Document Manager
        • Orders
          • Save Sale Order
          • Save Return Order
        • Orchestrated Orders
          • Orchestrated Order
          • Orchestrated Return order
          • Orchestrated Update order
        • Cart
          • Cart Validation
          • Cart Full Validation
        • Sales
          • Save receipt
          • Salve only Order
          • Replace or update sale
          • Get last digital order
        • Warehouse
          • Save Entry from supplier
          • Save Transfer document
          • Save Free Entry
        • Purchase
          • Save Purchase
        • Get Document
        • Update Document external references
      • Customer
        • Get Customer
        • Set Customer Opt-in
      • Loyalty vouchers
        • Get customer loyalty vouchers
        • Get loyalty vouchers at a time interval
        • Get last loyalty vouchers
      • Giftcard
        • Get Giftcard
        • Update Giftcard
        • Generate Gift Card Barcode
        • Gift Card PDF Generation
      • Stock
        • Get Stock
        • Get last stock
        • Insert Stock
  • 🚫 KeepIT
    • Authentication
    • Use cases
    • Articles (deprecated)
      • Get Articles
      • Insert/Update dimensional groups
      • Insert/Update price groupings
      • Insert/Update dimensions
      • Insert/Update attributes
      • Insert/Update hieararchies
      • Insert/Update seasons
      • Insert/Update articles
      • Insert/Update Articles Master data
      • Insert/Update Lists
      • Insert/Update Dimensions Groups
      • Create EAN13 barcode
      • Insert/Update Barcode
      • Assign dimensions to groupings
    • Price Lists (deprecated)
      • Insert price list
      • Add entity to price list
      • Add item price to price list
      • Insert sale profile
      • Insert sale period
      • Add item price to sale period
    • Stock (deprecated)
      • Get Stock
      • Get Stock Date
      • Get Stock CSV
      • Insert/Update Stock
    • Sales (deprecated)
      • Insert/Update sales
      • Delete sales
      • Upload printer sales archive
    • Deposit (deprecated)
      • Insert/Update deposits
    • Services
      • Insert/Update services
      • Delete services
    • Points
      • Insert/Update points
      • Calculate and Insert/Update Points
      • Delete points
    • Subjects
      • Check customers
      • Anonymize customers
      • Get subject data
      • Get customer discount
      • Insert/Update customer
      • Insert/Update billing customers
      • Insert/Update CRM customer
      • Insert/Update children
      • Change/Replacement card
      • Insert CRM user
    • Giftcards & Vouchers
      • Get giftcard
      • Insert/Update giftcards
      • Insert/Update Vouchers
    • Missed Opportunity
      • Get Lost Opportunities
      • Insert/Update missed opportunities
      • Delete missed opportunity
    • Documents (deprecated)
      • Insert documents
      • Get document
    • Catalogs
      • Get Catalog
      • Insert/update catalog
      • Insert/Update hierarchies item catalog
      • Insert/Update entity clusters
    • Suppliers (deprecated)
      • Insert/Update tailor
      • Insert/Update supplier
    • Export (deprecated)
      • Get Items Export
      • Get Barcodes Export
      • Get Prices Export
      • Get Customers Export
      • Get Suppliers Export
      • Get Sales Export
      • Get Movements Export
      • Get Vouchers Export
    • Configuration Mobile Shop (deprecated)
      • Insert/Update Entities
      • Insert Seller
    • Mappings
      • Insert Mappings
      • Get Mappings
  1. Use cases

Update an Orchestrated Order

Update an Orchestrated Order#

Use Case Description#

An external system (e.g., e-commerce frontend) creates a new sales order by calling saveOrder_v1.
The platform processes the order asynchronously and returns the created order identifier in a callback (only if transactionId was not provided).
Later the external system needs to change the order contents (for example remove a product) and calls updateOrder_v1 providing the same transactionId and rowId's returned by the platform (or the previously supplied transactionId) to update the exact same order.
VERY IMPORTANT INFO
Please note that the update and insert structure are identical; in effect, the order is replaced, so all information must be passed for a correct update.
If updateOrder_v1 is called with a different or missing transactionId the API returns an error indicating no documents were found.
Receipt Order
The order must not have already been finalized, that is, the administrative document that concludes the sale must not have been issued.

Actors#

Actors#

API Client: The system or user initiating the request.
4ws.trade: The backend system that processes the request.

Preconditions#

The external system must have the necessary permissions and access to the document creation service, please refer to Authentication.
Callback Endpoint (External Client): The callback used by Four Way Shop to asynchronously notify the client of success/failure and to return the order ID must be handled (How Testing callback response).
Monitoring / Alerting System: Handling integration errors and retries logs and warnings, as reported inBest Practices for Error Handling in External System.

Main Success Scenario#

1.
Client prepares full order JSON (see sample) and POSTs to Orchestrated Order.
2.
API gateway accepts request, returns HTTP 202/200 (depending on implementation) and schedules processing.
3.
Order Processor validates the payload (business rules, inventory holds, discounts).
4.
If transactionId is not provided, the Order Processor generates an internal transactionId/orderId.
5.
Once processing finishes successfully, the platform posts a callback to the client's callback URL containing the order reference and status.
6.
Client receives callback with transactionId (or orderId) and stores it.
7.
Client decides to remove a product and builds an updated order JSON containing the same transactionId and rowId's except for the removed line of course.
8.
Client POSTs updated order to updateOrder_v1.
9.
Order Processor finds the original order by transactionId, applies updates, revalidates totals and inventory, and returns success in callback with the updated order references.
Validate Cart
Before invoking the order update service it is useful to validate the cart or order via the API Cart Full Validation.

Alternate Flows#

Authentication Error: If the client does not provide valid credentials, an error response is returned.
Authentication Error Example
Missing or mismatched transactionId at update
Client calls updateOrder_v1 with a different or missing transactionId.
API responds (synchronously or via callback) with:
Missing or mismatched transactionId Error Example
Client must use the transactionId returned in the original callback or re-create the order.
Validation error on save
Processor finds invalid data (e.g., negative qty, missing required fields).
Callback contains validation error details; client must correct and resend.

JSON Structure for Sale Order Document (high-level schema)#

Below is the canonical structure and an annotated example.
Not all fields are strictly mandatory; required fields are marked.
VERY IMPORTANT INFO
Please note that the update and insert structure are identical; in effect, the order is replaced, so all information must be passed for a correct update.
Same transactionId and rowId's.

Example schema (JSON example trimmed for clarity)#

{
  "transactionId": "{{UUID}}-trs",         // optional on save, required on update
  "seller": "Marco Bianchi",
  "sellerId": "1001",
  "startDate": "2020-02-06 13:12:30",
  "endDate": "2020-02-06 13:22:19",
  "items": [
    {
      "rowId": "76c55f38-9586-462b-bdb6-9e45f9ba98b8",
      "rowType": "ITEM",
      "barcode": "010005600109",
      "itemCode": "BO00P794101",
      "description": "POLO IN COTONE PIQUET",
      "unitPrice": 19.9,
      "qty": 1,
      "taxRate": 22,
      "vatCode": 20,
      "rowTotal": 16.66,
      "discount": 10,
      "discountType": "P",
      "rowOrder": 1,
      "channel": "INSTORE"
    }
    // more items...
  ],
  "payments": [
    {
      "paymentType": "E",
      "paymentAmount": 10,
      "paymentCash": 10,
      "paymentCode": "21",
      "paymentDescription": "Carta di credito",
      "paymentProgr": "64231ea7-..."
    }
  ],
  "totals": {
    "totalDiscountAmount": 2.5,
    "total": 27.32,
    "vat": 6.01,
    "grandTotal": 33.32
  },
  "invoiceClient": { /* billing / customer info */ },
  "callback": "https://europe-west1-sinesy4wsplatform.cloudfunctions.net/fake-callback",
  "forceUndoAll": false
}
Notes on important fields
rowId: unique per item row — system may require stable rowId same of saveOrder_v1 if later updates reference the same row.
transactionId: external idempotency key. If client supplies it when creating the order, platform should honor it and return it back in callbacks. If omitted, platform generates one and returns it in the callback; that id must be reused to update the order.
items array in updateOrder_v1 normally contains the resulting items after the update (not a diff) — the platform will replace/reconcile the order content accordingly. Confirm with API contract if diffs are supported.

Callback Response#

When processing finishes (both for save and update), the platform POSTs a JSON payload to the callback URL. Example success callback (trimmed):
{
  "success": true,
  "message": "Order processed successfully",
  "transactionId": "11111111-2222-3333-4444-trs",
  "orderId": "ORD-20200206-0001",
  "docNumber": 1,
  "siteId": "501",
  "companyId": "TEMP1",
  "status": "PROCESSED",
  "totals": {
    "total": 27.32,
    "vat": 6.01,
    "grandTotal": 33.32
  },
  "items": [
    {
      "rowId": "76c55f38-9586-462b-bdb6-9e45f9ba98b8",
      "itemCode": "BO00P794101",
      "qty": 1
    }
  ],
  "timestamp": "2025-09-18T08:01:00Z"
}
Example error callback for update with unknown transactionId (or synchronous response from update endpoint):
{
  "success": false,
  "message": "No documents found for the provided transactionId"
}
external system and transactionId and rowId
Set a unique transactionId on saveOrder_v1 and then reuse it in updateOrder_v1, or if transactionId is omitted on saveOrder_v1 this will return the transactionId in the callback response, reuse it in updateOrder_v1 as a reference to the order to update.
Also rowId's must be the same on saveOrder_v1 and updateOrder_v1 as we report below the order will be replaced with the one provided on call body.

Sequence Diagram (Mermaid)#

Use this Mermaid diagram in markdown-capable docs or convert to an image in your docs tool:

Code Examples in Node.js#

Below are two example flows: (A) create order (save), (B) update order (remove an item). Use axios or node-fetch style — examples use axios for clarity. Always handle network errors and make your callbacks idempotent.
Best Practices
Please refer to Best Practices for Error Handling in External System for best practices on implementation.

A. Save order (create)#

B. Update order (remove a product)#

C. Minimal callback receiver (Express)#


Modified at 2025-10-08 13:56:01
Previous
Supplier Goods Entry From Purchase Order
Next
New Orchestrated Return Orders
Built with