pixiSetStock
Sets the stock quantity of an item on a bin to an absolute value by booking the difference as a scan-in or take-out stock movement.
Sets the quantity of one item on one bin to NewStockQty. The call does not overwrite the quantity directly. It calculates the difference to the current quantity and books that difference as a stock movement.
Steps:
- Checks the setting
API_Stock_Movements. If it is not enabled, the call returns a status row withStatus=ERRORand stops. - Checks that
SMORefis a stock movement operation (StockMovementOperations.SMOKey) whoseApplicationisAPI. If not, an error is raised. - Looks up the item by
EANUPC=EanUpc. - Reads whether the item requires batch numbers or best-before dates (item tags
-6and-7). If the item does not require them,BatchNumberandBestBeforeDateare ignored. If it requires them, they must be filled; otherwise nothing is booked. - Looks up the bin by
BinName. IfLocIdis given, only bins of that location are considered; otherwise the first bin with that name in any location is used, and its location is used for the booking. - Calculates the difference:
NewStockQtyminus the sum ofBinItemQTYof the item on that bin (all rows, regardless of batch or best-before date).- Difference > 0: books a scan-in (
Pixi_InvBinScanIn) of the difference. - Difference < 0: books a take-out (
Pixi_InvBinTakeOut) of the absolute difference. - Difference = 0: no booking.
- Difference > 0: books a scan-in (
- Before booking, the combination of
SMORefandSMTrefmust exist inStockMovementMatching; otherwise an error is logged and raised.- If
SMTrefis not given, the call replaces both values: for a scan-in it uses the API operationPutToStockand movement type0201, for a take-out the API operationTakeOutand movement type0301. - If
SMTrefis given, the passedSMORefandSMTrefare used.
- If
- Finally the item is queued for stock recalculation and shop export (
Pixi_ExportItemChangesToShop), also when nothing was booked.
The procedure has a return code: 0 = processed, 1 = item not found or required batch number / best-before date missing, 2 = bin not found. On success no result set is returned.
Notes
SMORefhas the defaultNULL, but the call always fails with SMO is not assigned to API if it is left out. Pass the key of an API stock movement operation.- The return codes
1and2are only the procedure's return value; no status row is returned. Depending on the client, a missing item or bin may therefore look like a success. - If
SMTrefis omitted, the passedSMORefis only used for the initial check and then replaced by thePutToStock/TakeOutoperation. - The difference is calculated over all batches and best-before dates on the bin, but booked with the given
BatchNumber/BestBeforeDate. For items with batches the result per batch may differ from what is expected. BestBeforeDatedefaults to'', which SQL Server converts to1900-01-01. This value is treated as empty, so items with a best-before date tag need a real date.- Without
LocId,TOP 1withoutORDER BYis used to pick the bin; if the bin name exists in several locations the choice is not deterministic. - Lookups use
NOLOCK. - The called procedures
Pixi_InvBinScanIn/Pixi_InvBinTakeOutreject quantities above the settingMaxStockOperationLimitand run in their own transaction; their base procedures are not attached. Errors inside the base procedures are logged vialog.InsertErrorand may not reach the caller. - Errors raised by the called procedures end in the CATCH block of this call, which writes an entry to
LogTableand raises an error with the content of the internal error variable. For errors not produced by this procedure itself, that message is empty, so the original error text is lost. - For the SMT is not matched error,
LogTablereceives two entries (one before raising, one in the CATCH block). - Every call that passes the initial checks inserts a row into
pixi.ItemRecalculateStockQueue, even if no booking was made or the item was not found.
Related calls
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
EanUpc
Required
|
varchar(13) string |
– |
EAN/UPC of the item ( Example: |
BinName
Required
|
varchar(50) string |
– |
Name of the bin ( Example: |
LocId
|
varchar(3) string |
NULL |
Location (warehouse) ID of the bin. If Example: |
NewStockQty
Required
|
int | – |
Target quantity of the item on the bin. Example: |
Username
|
varchar(50) string |
pipiSetStock |
User name recorded for the stock movement. Example: |
SMORef
|
int | NULL |
Key of the stock movement operation ( Example: |
SMTref
|
int | NULL |
Key of the stock movement type ( Example: |
BatchNumber
|
varchar(50) string |
– |
Batch number (Charge). Required for items with the batch number tag, ignored otherwise. Example: |
BestBeforeDate
|
datetime dateTime |
– |
Best-before date. Required for items with the best-before date tag, ignored otherwise. The default Example: |
Result set 1 · Only if the setting API_Stock_Movements is not enabled.
Status row with the error. On success the call returns no result set.
| Column | Type | Description |
|---|---|---|
Status
|
varchar(5) string |
Always |
StatusMessage
|
varchar(72) string |
Error text. |
Response example
<SqlRowSet1>
<row>
<Status>ERROR</Status>
<StatusMessage>Setting "API Calls Stock Movements" (API_Stock_Movements) is not enabled.</StatusMessage>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| ERROR | Setting "API Calls Stock Movements" (API_Stock_Movements) is not enabled. | The setting `API_Stock_Movements` is not set to 1. Enable it in the Pixi settings. |
| RAISERROR | Error Message: API pipiSetStockMultiple: SMO is not assigned to API! | `SMORef` is missing or is not a stock movement operation of application `API`. Pass the key of an API operation. |
| RAISERROR | API pipiSetStock Error message: SMT is not matched to SMO - please check Control Center - Stock Movements matching table! | The combination of operation and movement type used for the booking does not exist in `StockMovementMatching`. Maintain the matching in the Control Center or pass a matching `SMTref`. |
POST https://apigateway.descartes.com/tms/pixi/
Content-Type: text/xml; charset=utf-8
Authorization: Basic BASE64(USERNAME:PASSWORD)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiSetStock>
<EanUpc>4012345678901</EanUpc>
<BinName>A-01-02</BinName>
<!-- <LocId>001</LocId> -->
<NewStockQty>25</NewStockQty>
<!-- <Username>ShopSync</Username> -->
<!-- <SMORef>12</SMORef> -->
<!-- <SMTref>5</SMTref> -->
<!-- <BatchNumber>CH-2024-001</BatchNumber> -->
<!-- <BestBeforeDate>2025-12-31T00:00:00</BestBeforeDate> -->
</ns1:pixiSetStock>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
curl -X POST 'https://apigateway.descartes.com/tms/pixi/' \
--user 'USERNAME:PASSWORD' \
--header 'Content-Type: text/xml; charset=utf-8' \
--data-binary @- <<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiSetStock>
<EanUpc>4012345678901</EanUpc>
<BinName>A-01-02</BinName>
<!-- <LocId>001</LocId> -->
<NewStockQty>25</NewStockQty>
<!-- <Username>ShopSync</Username> -->
<!-- <SMORef>12</SMORef> -->
<!-- <SMTref>5</SMTref> -->
<!-- <BatchNumber>CH-2024-001</BatchNumber> -->
<!-- <BestBeforeDate>2025-12-31T00:00:00</BestBeforeDate> -->
</ns1:pixiSetStock>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML
<?php
$soapClient = new SoapClient(null, [
'login' => 'USERNAME',
'password' => 'PASSWORD',
'location' => 'https://apigateway.descartes.com/tms/pixi/',
'uri' => 'https://apigateway.descartes.com/tms/pixi/',
]);
$arguments = [
'EanUpc' => '4012345678901',
'BinName' => 'A-01-02',
// 'LocId' => '001',
'NewStockQty' => '25',
// 'Username' => 'ShopSync',
// 'SMORef' => '12',
// 'SMTref' => '5',
// 'BatchNumber' => 'CH-2024-001',
// 'BestBeforeDate' => '2025-12-31T00:00:00',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiSetStock', $soapArguments);
- SQL object:
- dbo.pipiSetStock