@stylusapparel/stylusop-api-node-wrapper
Version:
This is the official NodeJs wrapper for connecting to the StylusOP API
55 lines (50 loc) • 1.48 kB
JavaScript
const stylusWrapper = require('../index.js');
// Create the client
const stylusClient = stylusWrapper.createClient('YOUR_SECRET_TOKEN', {
username: 'creoapp',
sandBox: true,
apiVersion: 'v2',
tokenType: 'basic',
});
// Error handler //
function handleError(err) {
// Handle error //
if (err.status === 403 || err.status === 401 || err.errorCode === 'TOKEN_INVALID') {
// Unauthorized
console.error(`Error!\n(${err.errorCode}) ${err.message} ${JSON.stringify(err.rawError)}`);
} else {
// Other error
console.error(`Error!\n(${err.errorCode}) ${err.message}`);
}
}
// List orders... //
function listOrders() {
return stylusClient.orders.list({ limit: 2 }).then((orders) => {
console.log('Retrieved orders: ', orders);
return orders;
});
}
// Get an order's status //
function getOrderStatus() {
return stylusClient.orders.status('5efa364e87d09383ed5b85f0').then(({ status }) => {
console.log("Order's status: ", status);
return status;
});
}
// Get an order's activity log //
function getOrderActivity() {
return stylusClient.orders.activities('5efa364e87d09383ed5b85f0').then((activity) => {
console.log("Order's activty: ", activity);
return activity;
});
}
Promise.all([listOrders(), getOrderStatus(), getOrderActivity()])
.then((results) => {
const [orders, status, activity] = results;
console.log('Results: ', {
orders,
status,
activity,
});
})
.catch(handleError);