@stylusapparel/stylusop-api-node-wrapper v0.3.25
StylusOP API wrapper for Node.js (Official Module)
A NodeJS wrapper for connecting to Stylus order processing system using an authenticated token provided from Stylus. You can also view the full documentation of Stylus APIs here
Installing
$ npm install @stylusapparel/stylusop-api-node-wrapper --save
OR
$ yarn add @stylusapparel/stylusop-api-node-wrapper
Usage
Create a wrapper client for connecting to stylus:
const stylusWrapper = require("@stylusapparel/stylusop-api-node-wrapper");
const stylusClient = stylusWrapper.createClient("YOUR_API_SECRET_TOKEN",{ // client configurations
"username": "YOUR_USERNAME", // Required, your stylus provided "username"
"sandBox": true, // Optional, enable only if you are working in development mode
"apiVersion": "v2", // Optional, by default client connects to latest api version,
"tokenType": "basic" // Optional, You can use the JWT token or Basic Auth token. Allowed values: "basic", "jwt", Default is "basic"
});
-- Note: If a STYLUSOP_API_URL environment variable is found set, it will use that as the API endpoint and the "sandBox" setting will be ignored... --
Validate Secret Token
Check the validity of your secret token if needed before connecting to stylus processing functions:
stylusClient.isTokenValid()
.then((response) => {
console.log("success",response); // true
// Continue...
})
.catch((error) => {
console.log("error",error.errorCode,error.message);
});
OR
const response = await stylusClient.isTokenValid();
Push Order
Push an order to Stylus for production
stylusClient.orders.create({"ORDER_OBJECT"})
.then( (response) => {
console.log("order reference id",response.reference_id); // Very important! Store this 'reference_id' for future reference
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const response = await stylusClient.orders.create({"ORDER_OBJECT"});
More information on the format of order object can be view here
Note:- Store the reference_id
in your side for the future referencing this order from Stylus API
Fetch Orders
Fetch the previous orders details based on pagination or if no filter is provided this will return all the orders in descending order:
stylusClient.orders.list({
offset:0, // optional
limit:15, // optional,
dateRange:{ // optional, fetch orders created between the start and end date
start:"2020-07-03T00:00:00.130Z", // Follow the date format
end:"2020-08-03T00:00:00.130Z"
},
sort : 'created_date', //optional
sortOrder : 'DESC', //optional
orderId: 'ORDER_ID', //optional
orderStatus: "printed,shipped" // optional, comma saperated order status
})
.then( (orders) => {
console.log("orders",orders); // Array of order objects
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const orders = await stylusClient.orders.list({
offset:0, // optional
limit:15, // optional
dateRange:{ // optional, fetch orders created between the start and end date
start:"2020-07-03T00:00:00.130Z",
end:"2020-08-03T00:00:00.130Z"
},
sort : 'created_date', //optional
sortOrder : 'DESC', //optional
orderId: 'ORDER_ID', //optional
orderStatus: "printed,shipped" // optional, comma saperated order status
});
Fetch Order Details
Fetch the details of an order by its reference id:
stylusClient.orders.get("ORDER_REFERENCE_ID") // ORDER_REFERENCE_ID will be got from 'pushOrder' response
.then( (orderDetail) => {
console.log("order Detail",orderDetail); // Order detail object
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const orderDetail = await stylusClient.orders.get('ORDER_REFERENCE_ID');
Fetch Order Status
Fetch the status of an order by its reference id
client.orders.status("ORDER_REFERENCE_ID") // ORDER_REFERENCE_ID will be got from 'pushOrder' response
.then( (orderStatusDetails) => {
console.log("order status details",orderStatusDetails); // Order status details object
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const orderStatusDetails = await stylusClient.orders.status("ORDER_REFERENCE_ID");
Fetch Status of Multiple Orders
Fetch the status of mutiple orders by its reference id
client.orders.bulkStatus("ORDER_REFERENCE_ID1,ORDER_REFERENCE_ID3,ORDER_REFERENCE_ID3") // comma saperated ORDER_REFERENCE_ID
.then( (orderStatusDetails) => {
console.log("order status details",orderStatusDetails); // Order status details object
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const orderStatusDetails = await stylusClient.orders.bulkStatus("ORDER_REFERENCE_ID1,ORDER_REFERENCE_ID3,ORDER_REFERENCE_ID3");
Cancel Order
Cancel an exisitng order, which is already pushed to Stylus for production
stylusClient.orders.cancel("ORDER_REFERENCE_ID", { // ORDER_REFERENCE_ID will be got from 'pushOrder' response
"items": [ // optional, if you want to cancel the entire order pass 'items' as []
100001, // itemNumber of the order to cancel in case of partial order cancellation
100003 // itemNumber of the order to cancel in case of partial order cancellation
],
"reason": "Customer requested chargeback" // Optional, reason for cancelling the order
})
.then( (cancelStatus) => {
console.log("order activities",cancelStatus); // true, when cancellation success
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const cancelStatus = await stylusClient.orders.cancel("ORDER_REFERENCE_ID", { // ORDER_REFERENCE_ID will be got from 'pushOrder' response
"items": [ // optional, if you want to cancel the entire order pass 'items' as []
100001, // itemNumber of the order to cancel in case of partial order cancellation
100003 // itemNumber of the order to cancel in case of partial order cancellation
],
"reason": "Customer requested chargeback" // Optional, reason for cancelling the order
});
More information on the format of order cancel object can be view here
Update Order
Update an existing order, which is already pushed to Stylus for production
stylusClient.orders.update("ORDER_REFERENCE_ID",{"ORDER_UPDATE_OBJECT"}) // ORDER_REFERENCE_ID will be got from 'pushOrder' response
.then( (updateStatus) => {
console.log("order updated status",updateStatus); // true, when updation success
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const updateStatus = await stylusClient.orders.update("ORDER_REFERENCE_ID",{"ORDER_UPDATE_OBJECT"});
More information on the format of order update object can be view here
Fetch Order Activities
Fetch the activities of an order by its reference id
stylusClient.orders.activities("ORDER_REFERENCE_ID") // ORDER_REFERENCE_ID will be got from 'pushOrder' response
.then( (response) => {
console.log("order activities",response); // Array of order activity objects
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const response = await stylusClient.orders.activities("ORDER_REFERENCE_ID");
Search Products
Full/partial text based search for your products on its title, name, or skucode. If no search keyword is provided it will fetch all the products:
stylusClient.products.search({
offset:0, // optional, offset value for pagination implementation
limit:15, // optional, if not provided fetch all matching result
keyword : 'leggings', // optional, text for searching products
productIds: ['MERMTN1a70', 'MERMTN1a71'] // optional, select products based on array of product ids
})
.then( (products) => {
console.log("products",products); // Array of products
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const products = await stylusClient.products.search({
offset:0, // optional, offset value for pagination implementation
limit:15, // optional, if not provided fetch all matching result
keyword : 'leggings', // optional, string for search
productIds: ['MERMTN1a70', 'MERMTN1a71'] // optional, Array of productids
});
Find Variants
Fetch details of variant(s) by sku:
stylusClient.products.variants.find({
variantIds: ['B150_BK_OS', 'B150_BK_MD'] // optional, select variants based on array of variant ids
})
.then( (variants) => {
console.log("variants",variants); // Array of variants
})
.catch( (error) => {
console.log("error",error.errorCode,error.message,error.status);
});
// OR
const variants = await stylusClient.products.variants.find({
variantIds: ['B150_BK_OS', 'B150_BK_MD'] // optional, select variants based on array of variant ids
});
COMMON ERROR CODES
- TOKEN_MISSING - Secret token is missing in client config.
- USER_MISSING - Username is missing in client config.
- VERSION_ISSUE - apiVersion provided in the client config is not a valid/supported one.
- TOKEN_EXPIRE - Your token has been expired and can't access stylus service(s).
- TOKEN_INVALID - Your token is not valid or you dont have the access to stylus service(s).
- UNKNOWN_ERROR - Error occured due to internal connectivity issues at Stylus. side.
- PAGINATION_LIMIT_ERROR - When pass an unprocessable value for 'limit' in 'getOrders' function.
- ORDER_ID_INVALID - When pass an invalid order id in 'getOrder', 'updateOrder', or 'cancelOrder' function.
- ORDER_PAYLOAD_INVALID - When push an invalid order payload to Stylus for creating order.
- ORDER_PRODUCT_INVALID - When push an order payload with item(s) which is not mapped to Stylus.
- ORDER_ITEM_PROPERTY_INVALID - When push an order payload with item(s) having properties which is unknown to Stylus.
- ORDER_DUPLICATE - When push same order again or order contains item number of previous order.
- ORDER_STATUS_ISSUE - When try to change the status of an order which is already in a non-updatable status. For eg:- Tries to cancel an order which is already printed / shipped
- PRODUCT_NOT_FOUND - Product not found in our database or not found under the client's account.
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
9 months ago
9 months ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago