Stock
Stock drafts are used to manage inventory changes such as adding or removing products from stock. This process generally includes selecting a stock draft, creating a stock appendix, adding stock draft entries, booking the draft (if IsAutoBookPossible = true
), and ensuring successful completion.
Get Existing Stock Drafts
Method: POST
URL: {host_url}/api/inventory/StockDraft/GetAllStockDraftsDescriptors
Minimal Request:
{}
Response: Returns a list of descriptors of existing stock drafts. Each descriptor contains an
Id
that can be used for further operations.
Create Stock Appendix
Method: POST
URL: {host_url}/api/inventory/StockAppendicies/CreateStockAppendix
Minimal Request:
{
"stockDraftId": 1
}
Extended Request Example:
{
"stockDraftId": 1,
"description" -- optional: {
"value": "my appendix"
},
"stockAppendixSource" -- optional: {
"value": {
"sourceType": "invoice",
"sourceId": {
"value": [my_invoice_id]
},
"sourceIdentifier": {
"value": [my_invoice_identifier]
},
"alternativeAppendixNumber": {
"value": [invoice_identifier for example]
}
}
},
"userDefinedAppendixNumber": -- optional:{
"value": [my_invoice_identifier]
}
}
Stock appendix can be linked to invoices, sales orders, or other external sources. If using userDefinedAppendixNumber
, ensure it does not overlap with an existing stock appendix series.
Method returns structure with created appendixId
and appendixNumber
. AppendixId
will be used in next methods to create stock draft entries.
Create Stock Draft Entries
Method: POST
URL: {host_url}/api/inventory/StockDraftEntry/CreateStockDraftEntries
Minimal Request:
{
"stockAppendixId": [stock_appendix_id],
"stockDraftEntrySources": [collection_of_stock_draft_entry_sources]
}
Method allows to create multiple stock draft entries. Request property stockDraftEntrySources should contain a collection of StockDraftEntrySource objects of following format:
{
"stockAppendixId": [stock appendix ,
"stockDraftEntrySources": [
{
"customerActorId" --optional: {
"value": [my customer actor id]
},
"supplierActorId": --optional{
"value": [my supplier actor id]
},
"description": --optional{
"value": "[my stock draft entry description]"
},
"costPrice": --optional{
"value": [my cost price]
},
"salesPrice": --optional{
"value": [my sales price]
},
"source": --optional{
"value": {
"kind": "PurchaseDelivery = 1",
"identifier": "string"
}
},
"organizationalUnitId": -1,
"stockDate": "2020-06-26T06:04:13.637Z",
"productId": 1,
"variantId": [may be null],
"count": 1,
"instanceIds": --optional {
"value": [
1
]
},
"productLocationId": 1,
"externalReference": --optional{
"value": {
"sourceType": "[invoice for example]",
"sourceId": [invoice id for example]
}
},
"creditNoteExternalReference": --optional: {
"value": {
"sourceType": "string",
"sourceId": 0
}
}
}
]
}
Response of this method will contain references for created stock draft entries with their ids.
Some of stock drafts have a property IsAutoBookPossible = true
. In this case created stock draft entries will be booked just after creation and response will also contain Book operation result. In "Start booking of stock draft entries" and "Checking stock draft booking operation state" sections below is described how to analyze booking operation result.
Get Stock Draft Entries (Paged)
Method: POST
URL: {host_url}/api/inventory/StockDraftEntry/GetStockDraftEntriesPage
Minimal Request:
{
"stockAppendixId": 0,
"offset": 0,
"count": 10,
"includeOverallEntryCount": false
}
Extended request example:
{
"stockDraftId": 1,
"productId": {
"value": [product id filter]"
},
"description": {
"value": "[description filter]"
},
"costPrice": {
"value": {
"from": [cost price filter min],
"to": [cost price filter max]
}
},
"productCategoryIds": {
"value": [
product category ids to filter
]
},
"productLocationIds": {
"value": [
product location ids to filter
]
},
"organizationalUnitIds": {
"value": [
organizational unit ids to filter
]
},
"calculateTotalCostPrice": {
"value": true
},
"offset": 0,
"count": 10,
"includeOverallEntryCount": true
}
Use optional filters such as productId
, description
, costPrice
, productCategoryIds
, and organizationalUnitIds
to refine results.
Delete Stock Draft Entries
Delete a Single Entry
Method: POST
URL: {host_url}/api/inventory/StockDraftEntry/RemoveStockDraftEntry
Minimal Request:
{
"stockDraftEntryId": 1
}
Method allows to delete stock draft entry by Id
Delete All Entries from Stock Draft
Method: POST
URL: {host_url}/api/inventory/StockDraft/ClearStockDraft
Minimal Request:
{
"stockDraftId": 1
}
Method allows to delete all stock draft entries from stock draft.
Start Booking of Stock Draft Entries
Method: POST
URL: {host_url}/api/inventory/StockDraft/BookStockDraftEntries
Minimal Request:
{
"stockDraftId": 1
}
Extended request example:
{
"stockDraftId": 1,
"productCategoryIds": {
"value": [
0
]
},
"productLocationIds": {
"value": [
0
]
},
"organizationalUnitIds": {
"value": [
0
]
}
}
Method is intended to start stock draft booking operation. In response will be following structure:
"requisitionId": 1,
"state": {
"state": "1",
"resultCode": "1",
"faultedAppendixNo": 0,
"htmlErrorMessage": "string"
}
where requisitionId property contains the created stock booking operation requisition using which it is possible to track booking operation state.
Property state
contains state of booking operation at current moment. It is also contains property named state
, which is enum of type BookingOperationRequisitionStateKind
with following values:
InProgress = 1
Success = 2
Failed = 3
Booking stock drafts is an irreversible operation. Ensure the details are correct before initiating the process.
Checking Stock Draft Booking Operation State
Method: POST
URL: {host_url}/api/inventory/StockDraft/GetStockBookingOperationState
Minimal Request:
{
"id": [requisition_id]
}
Method allows to check state of stock draft booking operation. As Id should be used requisitionId of result of BookStockDraftEntries call. Response of method have following structure:
{
"errorOrValue": {
"value": {
"resultCode": "11",
"value": {
"state": "1",
"resultCode": "1",
"faultedAppendixNo": 0,
"htmlErrorMessage": "error_text"
}
}
}
}
Polling GetStockBookingOperationState
is necessary to confirm whether the booking succeeded (Success
) or failed (Failed
). If failed, analyze htmlErrorMessage
for details.