Close
logo

Mass Updating Dropship Providers

Git RepositoryEdit on Github
Last update: 2 years ago by luigi mangaReading time: 2 min

While managing a large database of dropship providers, it may be necessary to mass update some properties (e.g. commission rates).

This can be done programmatically by using Onport's API.

The below script shows how to set a commissionRate of 20.00 to all the Dropship Providers having a tag named test

import Bottleneck from 'bottleneck';
import pino from 'pino';
import request from 'request-promise-native';
const logger = pino({
prettyPrint: true,
});
const limiter = new Bottleneck({
maxConcurrent: 1,
minTime: 2000,
});
// Throttle the requests
const throttle = async (...params) => limiter.schedule(() => request(...params));
const headers = {
Authorization: `Bearer ${process.env.TOKEN}`,
};
const tags = ["test"];
const payload = {
commissionRate: "20.00"
};
const go = async () => {
logger.info('Fetching List of Dropship Providers');
const dropshipProviders = await throttle({
method: 'GET',
uri: `${process.env.API_HOST}/api/dropship-providers.json`,
json: true,
headers,
qs: {
where: {
internalTags: {
$contains: tags
}
}
}
});
logger.info('Making PUT request with following payload:');
logger.info(payload);
logger.info(dropshipProviders.length,'dropshipments to be updated');
for(const dropshipProvider of dropshipProviders) {
logger.info("Updating Dropship Provider ID",dropshipProvider.id);
const putDropshipProvider = await throttle({
method: 'PUT',
uri: `${process.env.API_HOST}/api/dropship-providers/${dropshipProvider.id}.json`,
json: true,
headers,
body: payload
});
if(putDropshipProvider && putDropshipProvider.id) {
logger.info("Dropship Provider",putDropshipProvider.id,"updated");
}else{
logger.info("Unable to update Dropship Provider",dropshipment.id);
}
}
};
go();

The script expects the following environment variables

API_HOST=https://api.jetti.io
TOKEN={{token}}
โŒจ๏ธ Dropship Providers โ€” Previous
Creating Dropship Provider Addresses
Next โ€” ๐Ÿ’ป Vendor Integration
Real Time Inventory Update