node-sykes-api v1.1.4
Sykes-API
This module lets you connect to Sykes web services using SOAP.
Note : Currently only two functionalities has been implemented : Order Loading and Inventory Level. These are not available to the public but are opened to pre-agreed IP addresses.
Installation
npm install node-sykes-api
Usage
In loopback:
var sykesAPI = require('node-sykes-api');
module.exports = function(InventoryLevel) {
InventoryLevel.beforeRemote('create', function(context, user, next) {
const servicesType = 'InventoryLevel';
const body = context.req.body;
const outputFormat = 'JSON'; //Optional
/*
Syntax:
sykesAPI(servicesType, body, [outputFormat,] function(err, res){
...
});
*/
sykesAPI(servicesType, body, outputFormat, function(err, res) {
if (err) {
next(err);
} else {
context.res.status(201).send({result: res});
}
});
});
};
In Express App:
var sykesAPI = require('node-sykes-api');
var express = require('express');
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.post('/sykes-api', function(req, res, next) {
const servicesType = 'InventoryLevel';
const body = req.body;
const outputFormat = 'JSON'; //Optional
sykesAPI(servicesType, body, outputFormat, function(err, response) {
if (err) {
next(err);
} else {
res.status(201).send({result: response});
}
});
});
var port = process.env.PORT || 8080;
var server = app.listen(port, function() {
console.log("Server is running on port " + port);
});
Options
servicesType
: This can take only string value based on the type of service/functionality. Currently only two functionalities has been implemented : Order Loading and Inventory Level.For Order Loading service :
servicesType
will take a string value 'OrderLoad'.For Inventory Level service :
servicesType
will take a string value 'InventoryLevel'.outputFormat
: This is optional argument. 'JSON' and 'XML' formats are supported. Default value isJSON
.For outputFormat = 'XML', the output would be in JSON format only, i.e. key-value pair, where value will be XML string.
{ "result" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><Warehouses xmlns=\"InventoryLevel_FromSykes.xsd\" ErrorMessage=\"\" RequestID=\"25669293\" RequestDateTime=\"2017-09-01 07:02:07\"><Warehouse><Name>PandGFemcare</Name><InventoryLevels><ItemPartNumber>83727497</ItemPartNumber><CurrentQuantity>0</CurrentQuantity></Warehouse></Warehouses>" }
body
: Request body should be in JSON format only.Sample Request JSON for Inventory Level:
{ "Warehouses": { "$": { "xmlns": "InventoryLevel_ToSykes.xsd", "ClientName": "PandGFemcare", "AllWarehouses": "0", "IsTest": "0", "SubmitDate": "2017-07-31" }, "Warehouse": { "Name": "PandGFemcare" } } }
where
$
is the xml attributes key.Sample Request JSON for Order Loading:
{ "Orders": { "$": { "xmlns": "OrderLoad_ToSykes.xsd", "SubmitDate": "2006-01-01", "ClientName": "PandGFemcare", "IsTest": "0" }, "Order": { "ClientOrderNumber": "735344ae-21a3-4954-9911-e7386a6d7be0", "CampaignCode": "Demi", "OrderDate": "2017-08-22", "PaymentType": "FOC", "Warehouse": "PandGFemcare", "Title": "", "Forename": "Sample", "Surname": "Sample", "Telephone": "", "Fax": "", "MobileTelephone": "", "EMailAddress": "sample", "CustomerUniqueID": "", "InvoiceAddress1": "sample", "InvoiceAddress2": "", "InvoiceAddress3": "", "InvoiceCity": "Sample", "InvoiceCountyState": "", "InvoicePostCode": "11111", "InvoiceCountryCode": "FRA", "ShipToAddress1": "Sample", "ShipToAddress2": "", "ShipToAddress3": "", "ShipToCity": "Sample", "ShipToCountyState": "", "ShipToPostCode": "11111", "ShipToCountryCode": "FRA", "DeliveryMethod": "Normal", "CurrencyCode": "EUR", "LanguageCode": "FRA", "DeliveryDate": "2006-01-01", "PromiseDate": "2006-01-01", "Comments": "", "OrderItem": { "LineNumber": "1", "ItemPartNumber": "83732765", "ItemSerialNumber": "", "Quantity": "1", "Price": "0", "TaxPercentage": "0", "TaxInclusive": "0", "ItemDescription": "Part 83732765", "LineComments": "", "CountryOfOrigin": "" } } } }
where
$
is the xml attributes key.
XML can also be passed as string inside the JSON. Where
_xml
is the key and value should be xml in string format.Sample Request JSON for Inventory Level with XML string:
{ "_xml" : "<Warehouses xmlns='InventoryLevel_ToSykes.xsd' ClientName='PandGFemcare' AllWarehouses='0' IsTest='0' SubmitDate='2017-07-31'><Warehouse><Name>PandGFemcare</Name></Warehouse></Warehouses>" }
Sample Request JSON for Order Loading with XML string:
{ "_xml" : "<Orders xmlns='OrderLoad_ToSykes.xsd' SubmitDate='2006-01-01' ClientName='PandGFemcare' IsTest='0'> <Order> <ClientOrderNumber>735344ae-21a3-4954-9911-e7386a6d7be0</ClientOrderNumber> <CampaignCode>Demi</CampaignCode> <OrderDate>2017-07-31</OrderDate> <PaymentType>FOC</PaymentType> <Warehouse>PandGFemcare</Warehouse> <Title></Title> <Forename>Sample</Forename> <Surname>Sample</Surname> <Telephone></Telephone> <Fax></Fax> <MobileTelephone></MobileTelephone> <EMailAddress>sample</EMailAddress> <CustomerUniqueID></CustomerUniqueID> <InvoiceAddress1>sample</InvoiceAddress1> <InvoiceAddress2></InvoiceAddress2> <InvoiceAddress3></InvoiceAddress3> <InvoiceCity>Sample</InvoiceCity> <InvoiceCountyState></InvoiceCountyState> <InvoicePostCode>11111</InvoicePostCode> <InvoiceCountryCode>FRA</InvoiceCountryCode> <ShipToAddress1>Sample</ShipToAddress1> <ShipToAddress2></ShipToAddress2> <ShipToAddress3></ShipToAddress3> <ShipToCity>Sample</ShipToCity> <ShipToCountyState></ShipToCountyState> <ShipToPostCode>11111</ShipToPostCode> <ShipToCountryCode>FRA</ShipToCountryCode> <DeliveryMethod>Normal</DeliveryMethod> <CurrencyCode>EUR</CurrencyCode> <LanguageCode>FRA</LanguageCode> <DeliveryDate>2006-01-01</DeliveryDate> <PromiseDate>2006-01-01</PromiseDate> <Comments></Comments> <OrderItem> <LineNumber>1</LineNumber> <ItemPartNumber>83732765</ItemPartNumber> <ItemSerialNumber></ItemSerialNumber> <Quantity>1</Quantity> <Price>0</Price> <TaxPercentage>0</TaxPercentage> <TaxInclusive>0</TaxInclusive> <ItemDescription>Part 83732765</ItemDescription> <LineComments></LineComments> <CountryOfOrigin></CountryOfOrigin> </OrderItem> </Order> </Orders>" }