1.0.1 • Published 6 years ago
shoplo-multi-client v1.0.1
Shoplo Multi API node Client
This sdk enables node developers to communicate with Shoplo Multi API with an oauth 2 authentication. More detailed info about api
Requirements
- node (6, 8 or 9)
Installation
npm install --save shoplo-multi-client
Resources
- application
- category
- channel
- channel_product
- chart
- customer
- form
- notification
- order
- product
- search
- shop
- store
- tracking
- user
Example
Authentication using oauth 1.
const ShoploMultiClient = require('shoplo-multi-client');
const session = require('express-session');
const express = require('express');
const config = {
"callbackUrl": "http://localhost:8080/callback",
"clientKey": "CLIENT_KEY",
"clientSecret": "CLIENT_SECRET",
"scope": ['scope_read_order', 'scope_write_order', 'scope_read_customer', 'scope_write_customer', 'scope_read_product', 'scope_write_product']
};
const shoploMultiClient = new ShoploMultiClient(config);
const app = express();
app.use(session({
secret: 'SOME_SECRET',
resave: true,
saveUninitialized: true
}));
app.get('/', (req, res) => {
res.redirect(shoploMultiClient.getAuthorizeUrl());
});
app.get('/callback', async (req, res) => {
const rsp = await shoploMultiClient.getAccesToken(req.originalUrl);
console.log(rsp.accessToken);
res.send(rsp.accessToken);
});
app.get('/me', async (req, res) => {
const rsp = await shoploMultiClient.getAccount();
res.send(rsp.data);
});
app.listen(8080, () => console.log('Server is running'));
Orders resource.
const config = {
"callbackUrl": "http://localhost:8080/callback",
"clientKey": "CLIENT_KEY",
"clientSecret": "SECRET_KEY",
"scope": ['scope_read_order', 'scope_write_order', 'scope_read_customer', 'scope_write_customer', 'scope_read_product', 'scope_write_product'],
"accessToken": 'ACCESS_TOKEN',
"refreshToken": 'REFRESH_TOKEN'
};
const shoploMultiClient = new ShoploMultiClient(config);
app.get('/orders', async (req, res) => {
const orderResource = new OrderResource(shoploMultiClient);
const rsp = await orderResource.getOrders();
const rsp = await orderResource.getOrders(18, { "with": ['order.items', 'order.fulfillments', 'order.addresses'] });
const rsp = await orderResource.getOrderTimeline(18);
const updateOrder = {
"note": "lorem ipsum dolor sit emet",
"financial_status": "paid"
};
const rsp = await orderResource.updateOrder(18, updateOrder);
const orderFulfillment = {
"tracking_company": "DPD",
"tracking_numbers": ["123456789"],
"tracking_urls": ["https://tracktrace.dpd.com.pl/EN/parcelDetails?typ=1&p1=123456789"],
"tracking_data": [],
"status": "fulfilled"
};
const rsp = await orderResource.createOrderFulfillment(18, orderFulfillment);
const rsp = await orderResource.updateOrderFulfillment(18, 112, orderFulfillment);
const rsp = await orderResource.deleteOrderFulfillment(18, 112);
res.send(rsp.data);
});
Channel Products resource.
const config = {
"callbackUrl": "http://localhost:8080/callback",
"clientKey": "CLIENT_KEY",
"clientSecret": "SECRET_KEY",
"scope": ['scope_read_order', 'scope_write_order', 'scope_read_customer', 'scope_write_customer', 'scope_read_product', 'scope_write_product'],
"accessToken": 'ACCESS_TOKEN',
"refreshToken": 'REFRESH_TOKEN'
};
const shoploMultiClient = new ShoploMultiClient(config);
app.get('/channel-products', async (req, res) => {
const channelProductResource = new ChannelProductResource(shoploMultiClient);
const rsp = await channelProductResource.getChannelProducts(2266);
const details = {
"title":"Bulb lamp graphite",
"description":"lorem ipsum"
};
const rsp = await channelProductResource.patchChannelProductDetails(2266, 10, details);
const detailsData = {
"title": "Bulb lamp metal",
"data": {
"short_description":"lorem ipsum",
"url":"bulb-lamp-graphite",
"width":"5",
"height":"5",
"depth":"5",
"diameter":"5",
"tax":"23",
"vendor":null,
"tags":[
"test"
],
"metadata":{
"meta_title":null,
"meta_description":null,
"meta_keywords":null
}
}
};
const rsp = await channelProductResource.updateChannelProductDetails(2266, 10, detailsData);
const image = {
"src": "https://assets.shoplo.io/webpage/images/brandhub/logo@2.png",
"position": "2"
};
const rsp = await channelProductResource.createChannelProductImage(10, image);
res.send(rsp.data);
});