API reference · Orders

Import External Order

POSThttps://api.sandbox.cws.digital/v1/order-importIn homologation

Description

Records in CWS an order placed outside the platform, such as a sale from your ERP, with customer, items, delivery, payment and status history.

The order goes into your store, with you as the seller. To record the order of another seller or in another store, send their documents: see Order seller and store.

How to identify the product

Each item must carry one of these forms. Items of the same order can use different forms.

FormFields
By manufacturer databrand, mfrPartCode and composition, all three together.
By attributeskuAttributeName and skuAttributeValue, both together.

The examples use the sandbox test product: replace warehouseId with the id of one of your warehouses and termInternalCode with a payment term of your store.

Request body

Content-Typeapplication/jsonRequired
Edit the body with
FieldTypeRequiredDescriptionValue
externalOrderIdstringYes

Order id in your system. Up to 100 characters. See Repeated externalOrderId returns the existing order.

orderDatestringYes

Order date and time, with the time zone. Cannot be in the future.

sellerDocumentstringNo

CPF or CNPJ of the seller, when it is not you. See Order seller and store.

storeDocumentstringNo

CPF or CNPJ of the owner of the order store, when it is not yours.

stockReductionobjectYes

Stock deduction of the order. See Stock deduction.

Fields in stockReduction

sendWebhookbooleanNo

true notifies the stores through the orders webhook. See Webhook.

customerobjectYes

Order customer. See Customer.

Fields in customer

deliveryAddressobjectConditional

Delivery address. Required when there is no pickupInStoreAddressId.

Fields in deliveryAddress

pickupInStoreAddressIdintegerConditional

Pickup point id. Required when there is no deliveryAddress.

freightobjectConditional

Delivery freight. Required when you send deliveryAddress.

Fields in freight

cancelReasonstringNo

Description of the cancellation reason. Up to 255 characters. Only with final status CANCELED; see Cancellation reason.

paymentsarray of objectYes

Payment term of the order, with exactly one item. See Payment.

Fields in payments[]

itemsarray of objectYes

Order items, from 1 to 100.

Fields in items[]

totalsobjectYes

Order values. See Totals.

Fields in totals

statusHistoryarray of objectYes

Status history, with at least one item. The last one is the order status.

Fields in statusHistory[]

externalAttributesarray of objectNo

Free data saved in the order.

Fields in externalAttributes[]

stockReduction
FieldTypeRequiredDescriptionValue
enabledbooleanYes

true deducts the stock of the items.

onInsufficientstringConditional

What to do when the balance is short. Required when enabled is true.

Allowed values:REJECTZERO_STOCK
customer
FieldTypeRequiredDescriptionValue
namestringYes

Customer name.

documentTypestringYes

Type of the customer document.

Allowed values:CPFCNPJ
documentstringYes

CPF or CNPJ of the customer, with or without mask.

emailstringNo

Customer email.

phonestringNo

Customer phone.

stateRegistrationstringNo

State registration. Saved only when the customer is created.

deliveryAddress
FieldTypeRequiredDescriptionValue
recipientNamestringNo

Name of the recipient.

zipcodestringYes

ZIP code, with or without hyphen.

streetstringNo

Street.

numberstringNo

Street number.

complementstringNo

Address complement.

neighborhoodstringNo

Neighborhood.

citystringNo

City.

statestringNo

State.

freight
FieldTypeRequiredDescriptionValue
typestringNo

Freight type. Up to 255 characters. When absent, EXTERNAL_ORDER applies.

namestringYes

Freight name, such as the carrier's. Beyond 80 characters, it is cut.

valuenumberNo

Freight value. Cannot be negative.

deliveryTimeDaysintegerNo

Delivery time, in days. Cannot be negative.

trackingCodestringNo

Tracking code. Up to 255 characters.

trackingUrlstringNo

Tracking link. Up to 255 characters.

Items of payments[]
payments[]
FieldTypeRequiredDescriptionValue
termInternalCodestringYes

Internal code of the custom payment term.

conditionInternalCodestringNo

Internal code of the term condition.

Items of items[]
items[]
FieldTypeRequiredDescriptionValue
brandstringConditional

Product brand. Goes together with mfrPartCode and composition.

mfrPartCodestringConditional

Manufacturer code. Goes together with brand and composition.

compositionstringConditional

Product composition, such as UNITARY. Goes together with brand and mfrPartCode.

skuAttributeNamestringConditional

Name of the product attribute. Goes together with skuAttributeValue.

skuAttributeValuestringConditional

Value of the product attribute. Goes together with skuAttributeName.

warehouseIdintegerNo

Item warehouse id. See Warehouse.

partnerPartCodestringNo

Product code in your store. Up to 255 characters.

quantityintegerYes

Quantity from the real stock. Cannot be negative.

virtualQuantityintegerYes

Quantity from the virtual stock. Cannot be negative; added to quantity, it must be above 0.

unitPricenumberYes

Unit price paid. Greater than 0.

listPricenumberNo

Full unit price, without discount. Greater than 0. When absent, unitPrice applies.

situationstringNo

Item situation, saved in the items tracking with all units of the item (quantity + virtualQuantity). Up to 100 characters. See Get Items Tracking - Store.

leadTimeDaysintegerNo

Item availability time, in days. Cannot be negative. When absent, 0 applies.

totals
FieldTypeRequiredDescriptionValue
subtotalnumberNo

Sum of the items.

freightnumberNo

Freight value in the total.

discountnumberNo

Discount value.

interestnumberNo

Installment interest.

totalnumberYes

Order total value.

Items of statusHistory[]
statusHistory[]
FieldTypeRequiredDescriptionValue
statusstringYes

Order status on that date.

Allowed values:PRE_ORDERAWAITING_PAYMENTSTORE_PAYMENTPAYMENT_APPROVEDWITHOUT_CREDIT_LIMITREADYSHIPPEDDELIVEREDCOMPLETEDCANCELEDSTRAYEDRETURNED
datestringYes

Status date and time, with the time zone.

Items of externalAttributes[]
externalAttributes[]
FieldTypeRequiredDescriptionValue
namestringYes

Data name. Up to 200 characters; externalCode is reserved.

valuestringNo

Data value.

Business rules

Repeated externalOrderId returns the existing order

The same externalOrderId, for the same seller, is imported only once. A new submission responds 409 with the ids of the order already imported, and nothing is saved.

Order seller and store

What you sendSellerStore
No documentYouYours
Only sellerDocumentThe owner of the documentYours
Only storeDocumentYouThe one of the document owner
BothThe owner of sellerDocumentThe one of the owner of storeDocument

With sellerDocument, you must be the seller or the store owner. When the seller is not the store owner, both must have an authorized partnership. Outside these conditions, the response is 404.

Warehouse

All items of the order leave from the same warehouse. The item warehouseId applies or, without it, the seller's default import warehouse.

When the seller does not yet have stock of the product in the warehouse, the stock is created with zero quantity.

Stock deduction

With stockReduction.enabled: true, the order deducts quantity and virtualQuantity of each item. An order with final status CANCELED, STRAYED or RETURNED does not deduct.

When the balance is short, stockReduction.onInsufficient applies:

ValueEffect
REJECTThe order is refused with 422, and insufficient lists the items without balance, with column indicating the missing stock: quantity (real) or virtual_quantity (virtual).
ZERO_STOCKThe stock without balance goes to zero, and the order is saved.

Payment

Send in payments exactly one custom payment term of the order store, by termInternalCode. A term linked to a credit limit is refused.

Delivery or pickup

Send deliveryAddress with freight for delivery, or pickupInStoreAddressId for pickup. For delivery, the address is located or added to the customer registration.

For pickup, the point must belong to the seller and serve the order warehouse, and the customer must have a registered address.

Customer

The customer is looked up in the order store and, if not found, created with the customer data. The stateRegistration is saved only on creation.

Status and dates

The order status is the last one in statusHistory. The items come in date order, without the same status repeated on the same date.

Send orderDate and the statusHistory dates with the time zone: 2026-09-01T08:30:00-03:00. A date without time zone refuses the request with 400.

Cancellation reason

An order with final status CANCELED can carry in cancelReason the description of a cancellation reason registered in CWS. A description without registration refuses the order with 422.

Totals

The totals values are saved as you send them, without checking against the items.

Webhook

With sendWebhook: true, the orders webhook notifies the stores with active external integration: the order store and the seller store.

Responses

  • 401

    Missing, malformed or expired token.

Try it

Sandbox

Language

Credentials

Access token: saved in this tab and used on every endpoint.

Each token only reaches the partner's own data and that of the branches with an authorized link.

Don't have sandbox credentials yet? See how to request them

Request

cURL
curl --request POST \
  --url 'https://api.sandbox.cws.digital/v1/order-import' \
  --header 'Authorization: Bearer <access_token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "externalOrderId": "ERP-2026-000123",
  "orderDate": "2026-09-01T08:30:00-03:00",
  "stockReduction": {
    "enabled": true,
    "onInsufficient": "REJECT"
  },
  "sendWebhook": false,
  "customer": {
    "name": "Ana Paula Ribeiro",
    "documentType": "CPF",
    "document": "466.935.373-08",
    "email": "ana.ribeiro@exemplo.com.br",
    "phone": "11987654321"
  },
  "deliveryAddress": {
    "recipientName": "Ana Paula Ribeiro",
    "zipcode": "01310-100",
    "street": "Avenida Paulista",
    "number": "1578",
    "complement": "Conjunto 42",
    "neighborhood": "Bela Vista",
    "city": "São Paulo",
    "state": "SP"
  },
  "freight": {
    "name": "Transportadora Exemplo",
    "value": 25.9,
    "deliveryTimeDays": 5
  },
  "payments": [
    {
      "termInternalCode": "BOLETO-30-DIAS"
    }
  ],
  "items": [
    {
      "brand": "Bosch",
      "mfrPartCode": "TESTE-API-001",
      "composition": "UNITARY",
      "warehouseId": 1001,
      "partnerPartCode": "PRODUTO-TESTE-001",
      "quantity": 2,
      "virtualQuantity": 0,
      "unitPrice": 89.9,
      "listPrice": 99.9
    }
  ],
  "totals": {
    "subtotal": 179.8,
    "freight": 25.9,
    "discount": 20,
    "total": 205.7
  },
  "statusHistory": [
    {
      "status": "PAYMENT_APPROVED",
      "date": "2026-09-01T08:35:00-03:00"
    }
  ]
}'

Response

Click Try it to see the real response here, or pick a documented example: