OrderType 1) and sales orders (OrderType 2) use the same endpoints.
Required fields
OrderType:1purchase order,2sales order. It cannot be changed after the order is created (6015).OrderNumber: unique within the company for the sameOrderType, at most 10 characters (6002). Send"Next"on create to generate it from the company’s number series: ALSİPNO for purchase orders and SATSİPNO for sales orders."Next"cannot be sent on update (6003).Date: the order date. If you send a time it is stored as the order time, otherwise the current time is used.CustomerCode: a customer the user can see. The order is written with the customer’s address: the invoice address when the customer has one, otherwise the first address.Lines: at least one line (6012).
CurrencyCode. The document currency is derived from the lines (the single currency they share, or the company’s default currency when they differ) and returned as CurrencyCode. AverageExchangeRate is not sent either; it is filled from the lines (a value in the request is ignored): when all lines share one currency, the average of the line exchange rates weighted by the line amounts (the sum of AmountExcludingTax × ExchangeRate divided by the sum of AmountExcludingTax); when the lines have different currencies, 1. See currencies.
DueDays (payment term in days) is stored with the order and used for the due date of the customer movement below; the movement’s rate is the order’s AverageExchangeRate, filled from the lines.
Customer movement
TheCreateCustomerMovement field decides whether the order is reflected on the customer’s account. You do not send a separate request or field: the movement is written together with the order, in the same transaction.
When true, the order amount (GrandTotal, filled from the lines) is written to the customer’s account as follows:
The movement takes its date, time, document number (the order number), description, currency (
CurrencyCode) and rate (AverageExchangeRate) from the order. The due date is Date + DueDays; when DueDays is 0 there is no due date. In responses, CreateCustomerMovement shows whether the order has a customer movement.
On update the movement is brought in line with the request:
The customer movement of a sales order is also checked against the customer’s risk limit when the customer’s
RiskAction is 2; an order that would exceed it is rejected with 6020. Purchase orders are not checked. On update, the check runs only when the customer changes or the amount increases.
Approvals and status
When an order is created, the following are assigned automatically; there are no request fields for them:- Approvals: for each of the company’s active order approval definitions whose minimum amount is below
GrandTotaland that applies to the order type (a definition applies to both purchase and sales, or only to the order’s type), a “pending” approval record is created, in the definition’s sequence order. - Status: if the company has a default order status defined, the order starts with that status. Otherwise the status stays empty.
StatusId and StatusName in responses show the order’s current status. Update and partial update do not change approvals or the status, and approvals are not recalculated even if GrandTotal changes.
Lines
- The product is given with
ProductCode(the product’s code) orECommerceProductCode(its e-commerce integration code); one of them is required. If both are sent,ProductCodeis used.UnitCodeis required. The unit must be one of the product’s own units (its main unit, or its second/third unit). Quantitymust be greater than 0;UnitPricecannot be negative and must exclude VAT.VatIncludedis ignored (it is still accepted so that existing requests keep working).CurrencyCodeis required on every line.ExchangeRatemust be1when the line currency is the company’s default currency; otherwise it is required and must be greater than 0.Discountsis the list of the line’s discount rates. They are applied one after another in list order: 10, 10 and 10 give a 27.1% line discount. Leave the list empty when the line has no discount.LineGroupNameis optional and comes from the line groups definition.WarehouseNameis optional and must be one of the company’s warehouses (6112).- Lines have no ID: their position in the list is their position in the order, and an update replaces all lines.
Main unit quantity
Quantity is in the line’s unit. MainUnitQuantity in responses is the same quantity expressed in the product’s main unit; it is calculated by the API and you do not send it. It is negative on a sales order and positive on a purchase order.
- If
UnitCodeis the product’s main unit,MainUnitQuantityequalsQuantity. - If it is the product’s second or third unit, the multiplier of that unit is found first: the quantity the product defines for that unit divided by its counter quantity (a counter quantity of
0counts as1).MainUnitQuantity=Quantity/ multiplier.
100 and a counter quantity of 3 for its second unit, the multiplier is 33.33, and a line of 1000 in the second unit is 30 in the main unit. If the product defines no quantity for that unit (0), the main unit quantity cannot be calculated and the line is rejected with 6113.
Editing and deleting
Editing and deleting are not restricted by the order’s status or by whether it has been transferred to other documents (despatch, invoice). The only restrictions are a closed customer movement (see above) and other records (for example a quote or an opportunity) referring to the order (6014).
Sharing
SharingCode limits who can see the order: empty means visible to everyone, otherwise it must be one of the user’s sharing codes (6011). Orders the user cannot see return 404.