API reference · Orders
Import External Order
https://api.sandbox.cws.digital/v1/order-importIn homologationDescription
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.
| Form | Fields |
|---|---|
| By manufacturer data | brand, mfrPartCode and composition, all three together. |
| By attribute | skuAttributeName 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
application/jsonRequired| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| externalOrderId | string | Yes | Order id in your system. Up to 100 characters. See Repeated | |
| orderDate | string | Yes | Order date and time, with the time zone. Cannot be in the future. | |
| sellerDocument | string | No | CPF or CNPJ of the seller, when it is not you. See Order seller and store. | |
| storeDocument | string | No | CPF or CNPJ of the owner of the order store, when it is not yours. | |
| stockReduction | object | Yes | Stock deduction of the order. See Stock deduction. Fields in stockReduction | |
| sendWebhook | boolean | No |
| |
| customer | object | Yes | Order customer. See Customer. Fields in customer | |
| deliveryAddress | object | Conditional | Delivery address. Required when there is no Fields in deliveryAddress | |
| pickupInStoreAddressId | integer | Conditional | Pickup point id. Required when there is no | |
| freight | object | Conditional | Delivery freight. Required when you send Fields in freight | |
| cancelReason | string | No | Description of the cancellation reason. Up to 255 characters. Only with final status | |
| payments | array of object | Yes | Payment term of the order, with exactly one item. See Payment. Fields in payments[] | |
| items | array of object | Yes | Order items, from 1 to 100. Fields in items[] | |
| totals | object | Yes | Order values. See Totals. Fields in totals | |
| statusHistory | array of object | Yes | Status history, with at least one item. The last one is the order status. Fields in statusHistory[] | |
| externalAttributes | array of object | No | Free data saved in the order. Fields in externalAttributes[] |
| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| enabled | boolean | Yes |
| |
| onInsufficient | string | Conditional | What to do when the balance is short. Required when Allowed values: REJECTZERO_STOCK |
| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| name | string | Yes | Customer name. | |
| documentType | string | Yes | Type of the customer document. Allowed values: CPFCNPJ | |
| document | string | Yes | CPF or CNPJ of the customer, with or without mask. | |
| string | No | Customer email. | ||
| phone | string | No | Customer phone. | |
| stateRegistration | string | No | State registration. Saved only when the customer is created. |
| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| recipientName | string | No | Name of the recipient. | |
| zipcode | string | Yes | ZIP code, with or without hyphen. | |
| street | string | No | Street. | |
| number | string | No | Street number. | |
| complement | string | No | Address complement. | |
| neighborhood | string | No | Neighborhood. | |
| city | string | No | City. | |
| state | string | No | State. |
| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| type | string | No | Freight type. Up to 255 characters. When absent, | |
| name | string | Yes | Freight name, such as the carrier's. Beyond 80 characters, it is cut. | |
| value | number | No | Freight value. Cannot be negative. | |
| deliveryTimeDays | integer | No | Delivery time, in days. Cannot be negative. | |
| trackingCode | string | No | Tracking code. Up to 255 characters. | |
| trackingUrl | string | No | Tracking link. Up to 255 characters. |
payments[]| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| termInternalCode | string | Yes | Internal code of the custom payment term. | |
| conditionInternalCode | string | No | Internal code of the term condition. |
items[]| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| brand | string | Conditional | Product brand. Goes together with | |
| mfrPartCode | string | Conditional | Manufacturer code. Goes together with | |
| composition | string | Conditional | Product composition, such as | |
| skuAttributeName | string | Conditional | Name of the product attribute. Goes together with | |
| skuAttributeValue | string | Conditional | Value of the product attribute. Goes together with | |
| warehouseId | integer | No | Item warehouse id. See Warehouse. | |
| partnerPartCode | string | No | Product code in your store. Up to 255 characters. | |
| quantity | integer | Yes | Quantity from the real stock. Cannot be negative. | |
| virtualQuantity | integer | Yes | Quantity from the virtual stock. Cannot be negative; added to | |
| unitPrice | number | Yes | Unit price paid. Greater than 0. | |
| listPrice | number | No | Full unit price, without discount. Greater than 0. When absent, | |
| situation | string | No | Item situation, saved in the items tracking with all units of the item ( | |
| leadTimeDays | integer | No | Item availability time, in days. Cannot be negative. When absent, 0 applies. |
| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| subtotal | number | No | Sum of the items. | |
| freight | number | No | Freight value in the total. | |
| discount | number | No | Discount value. | |
| interest | number | No | Installment interest. | |
| total | number | Yes | Order total value. |
statusHistory[]| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| status | string | Yes | Order status on that date. Allowed values: PRE_ORDERAWAITING_PAYMENTSTORE_PAYMENTPAYMENT_APPROVEDWITHOUT_CREDIT_LIMITREADYSHIPPEDDELIVEREDCOMPLETEDCANCELEDSTRAYEDRETURNED | |
| date | string | Yes | Status date and time, with the time zone. |
externalAttributes[]| Field | Type | Required | Description | Value |
|---|---|---|---|---|
| name | string | Yes | Data name. Up to 200 characters; | |
| value | string | No | 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 send | Seller | Store |
|---|---|---|
| No document | You | Yours |
Only sellerDocument | The owner of the document | Yours |
Only storeDocument | You | The one of the document owner |
| Both | The owner of sellerDocument | The 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:
| Value | Effect |
|---|---|
REJECT | The 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_STOCK | The 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.