> For the complete documentation index, see [llms.txt](https://kb.logicerp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/orders/push/assign-stock-to-a-delivery-order.md).

# Assign Stock to a Delivery Order

Records that goods of a **delivery order** that is already in Logic ERP have been picked and packed. A delivery order lists sale-order goods to be dispatched; each of its lines has stock (a lot) set aside for it. With this endpoint you tell Logic ERP, item by item, how many units you packed and in which **packing box**. Logic ERP assigns that set-aside stock to the delivery order, takes the units off the line's pending quantity and remembers the box of every unit, ready for the delivery order to be invoiced or transferred later. It does **not** create a delivery order and does not change its items or quantities.

The usual flow: read the delivery order with [Get Delivery Orders](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/orders/pull/get-delivery-orders.md), pick and pack the goods, then send this request with the delivery order's number, the items, the quantities packed and the box numbers. The request uses the same shape as a Get Delivery Orders record, so you can send that record back with `Packing_Box_No` and `Quantity` filled in.

### **Endpoint**

| Name          | Detail                                   |
| ------------- | ---------------------------------------- |
| Address       | `https://your-server/api/SaveAssignedDO` |
| Method        | `POST`                                   |
| Authorization | Basic Auth                               |

The response envelope, dates, queueing and the common messages are explained in [How Every API Call Works](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/how-every-api-call-works.md). When request queueing is switched on for your API site, all requests to this endpoint run one at a time, whatever their branch.

### **Request fields**

Field names are not case-sensitive. Item codes and set names are matched as you send them – spaces in front of them are not removed; capital and small letters do not matter.

| Field                      | Type         | Required | Default                     | Meaning                                                                                                                                                                                                                                                         |
| -------------------------- | ------------ | -------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Doc_Code`                 | number       | Yes      | `0`                         | Logic ERP's internal number of the delivery order – `Doc_Code` in Get Delivery Orders.                                                                                                                                                                          |
| `DO_Branch_Code`           | number       | No       | the delivery order's branch | The branch of the delivery order (`Branch_Code` in [Get Branch Info](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/masters/pull/get-branch-info.md)). Left out or `0`, the delivery order's own branch is used. |
| `Doc_Prefix`, `Doc_Number` | text, number | No       | empty, `0`                  | The delivery order's number, as in Get Delivery Orders. Used only in the message for an item that is not on the delivery order.                                                                                                                                 |
| `LstItems`                 | list         | Yes      | empty list                  | What you packed – see below.                                                                                                                                                                                                                                    |
| `DisplayError`             | text         | No       | empty                       | `"1"` = when the request fails, `Message` carries the full technical detail instead of the reason.                                                                                                                                                              |

**`LstItems` – one entry per item and packing box**

| Field                | Type   | Required | Default | Meaning                                                                                                                                                                                                                                                                                                                                                         |
| -------------------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `LogicUser_Code`     | text   | Yes      | empty   | The item code shown in Logic ERP (`UserCode` in [Get Item Master](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/masters/pull/get-item-master.md)). When your Logic ERP is set to use additional item codes, an additional item code / barcode is accepted here too. For a set, the set's name – see `ItemType`. |
| `Quantity`           | number | Yes      | `0`     | Units packed in this box. Must be above `0`. Whole units only – a fraction is not assigned.                                                                                                                                                                                                                                                                     |
| `Packing_Box_No`     | text   | Yes      | empty   | The packing box the units are in, for example `B-0412`. Up to 30 characters are kept.                                                                                                                                                                                                                                                                           |
| `Packing_Box_Weight` | number | No       | `0`     | The box's weight. Saved for the box when it is not `0`; when several entries name the same box, the first entry's weight is used.                                                                                                                                                                                                                               |
| `BinCode`            | number | No       | `0`     | Only for a delivery order that works with bins: the bin the stock is taken from. When sent, only delivery-order lines of that bin are used.                                                                                                                                                                                                                     |
| `ItemType`           | text   | No       | empty   | `SET` = `LogicUser_Code` is the name of an item set; every unit then assigns each item of the set, in the set's quantities. Anything else = a single item.                                                                                                                                                                                                      |

**Ignored fields.** `AddlItemCode` (only `LogicUser_Code` is read), `Lot_MRP`, `MRP`, `DO_Txn_Code`, `Lot_Code`, `ItemDetCode`, `Packing`, `Packing_CF1`, `Packing_CF1_Desc`, `BinName`, and at the top: `Doc_Type`, `DO_Date`, `BranchCode_To`, `PartyUserCode`, `SO_Head_Code`, `SO_No`, `SO_Date`, `Customer_Name`, `SO_Delivery_Date`, `Action_Code`, `Logic_User_Name`, `CurrencyName`, `ExchangeRate`, `PickListDocCode`. They are accepted so that a Get Delivery Orders record can be sent back unchanged.

### **Rules Logic ERP applies**

* **Which line.** For each unit, Logic ERP takes the first line of the delivery order for that item that still has a pending quantity, limited to `BinCode` when you send it. When an item is on several lines, you cannot choose which line is used, and it is not necessarily the order in which Get Delivery Orders lists them.
* **Which stock.** The stock assigned is the lot set aside for that line (from the sale order), in its godown and bin, in the current financial year. You cannot choose another lot. For items tracked piece by piece, Logic ERP picks the next free piece of that lot.
* **Pending quantity.** Each assigned unit is taken off the line's pending quantity and off the stock set aside, and counted as stock on a delivery order. Assigning more units than are pending is refused (`No pending record found...`) and nothing is saved.
* **Boxes.** Every unit is recorded with its box. Boxes registered in Logic ERP's box master for this branch, and not yet linked to another document, are linked to the delivery order. For items that are not tracked piece by piece, a box that is already saved on the delivery order for the same item cannot be added to again – use a new box number.
* **Pick lists.** When the delivery order was sent for picking (a pick list exists for it), the pick list is updated with the boxes and the quantities packed, and the delivery-order lines that still have a pending quantity are released from the pick list.
* **Several requests.** A delivery order can be packed over several requests; each one assigns more units until nothing is pending.
* **Record of the change.** The delivery order is recorded as modified in Logic ERP's audit trail.
* **All or nothing.** If any entry fails, nothing from the request is saved.
* **No API settings.** This endpoint reads no settings of your API site and cannot be switched off per branch.
* Your Logic ERP licence must include the assign-stock-to-delivery-order (warehouse) API.
* **Short stock.** If the lot set aside for a line no longer has enough free stock in its godown, the request is refused with *Stock not available to assign Item : … in delivery order …* and nothing is saved.

> **Known issue – the "not on the delivery order" message shows your own number.** The message quotes `Doc_Prefix` and `Doc_Number` from your request, so it reads `DO Nummber : -0` when you did not send them. The delivery order checked is always the one in `Doc_Code`.

### **Example request**

```json
{
  "Doc_Code": 3187,
  "Doc_Prefix": "DO",
  "Doc_Number": 2214,
  "DO_Branch_Code": 2,
  "LstItems": [
    { "LogicUser_Code": "SHT1042", "Quantity": 6, "Packing_Box_No": "B-0412", "Packing_Box_Weight": 4.8 },
    { "LogicUser_Code": "TRS2210", "Quantity": 4, "Packing_Box_No": "B-0412" }
  ]
}
```

### **Response**

| Field           | Type         | Meaning                                       |
| --------------- | ------------ | --------------------------------------------- |
| `Status`        | true / false | `true` when the request was saved.            |
| `Message`       | text         | Empty when saved; the reason when not saved.  |
| `LastSavedCode` | number       | The `Doc_Code` you sent, when saved.          |
| `request_ID`    | text         | The ID of this request – quote it to support. |

### **Example response**

```json
{
  "Status": true,
  "Message": "",
  "LastSavedCode": 0,
  "request_ID": "c5a09e3d-7f21-4b8a-9d64-3e1f0b2a7c58"
}
```

### **Messages you may see**

With `"DisplayError": "1"`, every message comes with technical text around it – look for the reason in the first lines.

| Message                                                                                                                        | Meaning                                                                                                 | What to do                                                                |
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| `No Items Present in API Request...`                                                                                           | `LstItems` is empty.                                                                                    | Send at least one item.                                                   |
| `Cannot allow zero Doc_Code.`                                                                                                  | `Doc_Code` is `0` or missing.                                                                           | Send the delivery order's internal number.                                |
| `Unable to found Doc_Code : …`                                                                                                 | No delivery order has this internal number.                                                             | Check `Doc_Code` in Get Delivery Orders.                                  |
| `Packing BOX Number cannot be blank....for Item :…`                                                                            | An entry has no `Packing_Box_No`.                                                                       | Send the box number.                                                      |
| `Assign Quantity cannot be zero....for Item :…`                                                                                | `Quantity` is `0` or less.                                                                              | Send a quantity above `0`.                                                |
| `Invalid Item`                                                                                                                 | `LogicUser_Code` is not an item code.                                                                   | Send the code exactly as in Logic ERP.                                    |
| `Item : … not exists in selected delivery order. DO Nummber : …`                                                               | The item is not on the delivery order, or none of its lines is pending any more.                        | Check the delivery order; do not resend a request that was already saved. |
| `No pending record found...`                                                                                                   | More units were sent than are pending for the item (or for the bin you sent).                           | Send no more than the pending quantity.                                   |
| `Stock not available to assign Item : … in delivery order …`                                                                   | The lot set aside for the line does not have enough free stock left. Nothing was saved.                 | Check the lot's stock in Logic ERP.                                       |
| `Unable to found Item Code :… of Set : …`                                                                                      | With `ItemType` `SET`, an item of the set has no pending line on the delivery order. Nothing was saved. | Check the delivery order and the set.                                     |
| `Unable to found Item Code :…`                                                                                                 | The item is on the delivery order, but not in the bin you sent.                                         | Check `BinCode`.                                                          |
| `Unable to found Set : …`                                                                                                      | With `ItemType` `SET`, no set has this name.                                                            | Send the set's name exactly as in Logic ERP.                              |
| `Scanning not allowed if box No. is already saved in database for the same Item...`                                            | This box was already saved for the item on this delivery order.                                         | Use a new box number.                                                     |
| `Invalid Lot / Carton Code`                                                                                                    | The stock set aside for the line is not found in its godown for the current financial year.             | Check the sale order's reserved stock in Logic ERP.                       |
| `Bin not exist in Sale Order Reserve. Cann't Save. Aborting...` / `Bin not exist in against scaning. Cann't Save. Aborting...` | The delivery order works with bins, but the stock set aside has no bin.                                 | Correct the reservation in Logic ERP.                                     |
| `DO Un Assign Pending Quantity in Do Txn will go -ve...DO Txn Code:…`                                                          | The line would go below zero pending (usually two requests at the same time).                           | Read the delivery order again before resending.                           |
| `No free piece available in Lot / Carton Code : …`                                                                             | For an item tracked piece by piece, no free piece is left in the lot. Nothing was saved.                | Check the lot's stock in Logic ERP.                                       |
| Another technical error                                                                                                        | Saving failed inside Logic ERP; nothing was saved.                                                      | Retry once; if it repeats, send the `request_ID` to support.              |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/orders/push/assign-stock-to-a-delivery-order.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
