024623: Importing Stock items via Webservices
1. Overview
KCSL have added a new web service request to import stock items based on the current TSV Stock Importer.
2. Specification
Requirement from the development:
- The ability to import
their stock through Webservices.
- Added a new web service to import
stock items which is based on the existing TSV Stock Importer.
- This includes an error/summary response which translates the import result into an XML response.
- This is
limited to 25 items at a time so the XML can respond in a reasonable amount of
time.
- Fields are limited to the
fields that are available in the TSV stock importer.
Caveats:
- Only one barcode per item per
import. If multiple barcodes need to be imported, they will need to be done
separately.
- This development mimics the function of the
existing TSV stock importer via webservices – so only functionality that is
supported by the TSV importer is supported by this development.
3. Configuration
An updated application will be provided with this functionality.
4. Usage
After applying the above Configuration, typical steps for usage would include the following.
- There is a new webservice request called ‘ImportStockTSV’.
- See Figure 1.0 for an example request.
- The format of the request should match the format for the TSV stock importer.
- For more info on the mandatory/optional fields available, please see: /article/stock-import-tool/
- There is a 25-item limit to this request. Requests that exceed the 25 items will fail, and no items will be imported.
Fig. 1.0 – An example import request.
A copy of the above request that can be copied/pasted to test:
<soapenv:Body>
<urn:ImportStockTSV soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<StockData xsi:type="xsd:string">STOCK_CODE CONTROLLED SHORT_DESC STOCK_TYPE1 STOCK_TYPE2 STOCK_TYPE3 STOCK_TYPE4 BUY_PRICE SELL_PRICE
AAA_TEST_001 -1 Test Item 001 Products Testing 1.50 5.00
AAA_TEST_002 0 Test Item 002 Products Testing 0.49 4.99
</StockData>
</urn:ImportStockTSV>
</soapenv:Body>
5. Example Responses
There are various responses that can be returned. Some scenarios that may cause errors/warnings include:
- More than 25 stock items.
- Duplicate stock codes.
- Missing column headers.
- Missing compulsory fields.
- Incomplete fields against a stock item.
- Incorrect data - e.g. text in an integer field.
Successful Response
An example of a successful response:
<NS1:ImportStockTSVResponse>
<return xsi:type="xsd:string">2 lines imported, 0 lines skipped</return>
</NS1:ImportStockTSVResponse>
Too Many Items Error
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Error: Skipping import, please only import up to 25 items at a time.</faultstring>
<faultactor>EWebImportException</faultactor>
<detail>
<NS1:EWebServiceError xsi:type="NS1:EWebServiceError" xmlns:NS1="urn:WebServiceP">
<ExceptionClassName xsi:type="xsd:string">EWebImportException</ExceptionClassName>
<ExceptionInheritance xsi:type="xsd:string">EWebImportException,EWebServiceException,EKosException,Exception</ExceptionInheritance>
</NS1:EWebServiceError>
</detail>
</SOAP-ENV:Fault>
Duplicate Stock Codes Response
<NS1:ImportStockTSVResponse>
<return xsi:type="xsd:string">2 lines imported, 1 lines skipped
Skipped line due to duplicate ID: 2</return>
</NS1:ImportStockTSVResponse>
Missing Column Header Error
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Cannot import; ZZZ_TEST_CODE column not found</faultstring>
<faultactor>EStockImport</faultactor>
<detail>
<NS1:EWebServiceError xsi:type="NS1:EWebServiceError" xmlns:NS1="urn:WebServiceP">
<ExceptionClassName xsi:type="xsd:string">EStockImport</ExceptionClassName>
<ExceptionInheritance xsi:type="xsd:string">EStockImport,EKosException,Exception</ExceptionInheritance>
</NS1:EWebServiceError>
</detail>
</SOAP-ENV:Fault>
Missing Compulsory Field Response
<NS1:ImportStockTSVResponse>
<return xsi:type="xsd:string">1 lines imported, 1 lines skipped
Skipped line due to error saving: 2: Field [Stock Code] is COMPULSORY. Please make sure it has a value. [Technical info: Class = TKosStock, ID = 15878]</return>
</NS1:ImportStockTSVResponse>
Incomplete Fields Response
<NS1:ImportStockTSVResponse>
<return xsi:type="xsd:string">2 lines imported, 1 lines skipped
Skipped line due to insufficient data: ZZZ_TEST_001: Does not contain a full set of fields</return>
</NS1:ImportStockTSVResponse>
Incorrect Data Response
<NS1:ImportStockTSVResponse>
<return xsi:type="xsd:string">1 lines imported, 1 lines skipped
Skipped line due to error saving: ZZZ_TEST_001:
'test' is not a valid floating point value</return>
</NS1:ImportStockTSVResponse>