Skip to content

Instantly share code, notes, and snippets.

@serhiosipatron
Last active July 24, 2020 11:43
Show Gist options
  • Select an option

  • Save serhiosipatron/c357a6f0939678e9f084244aa14695c8 to your computer and use it in GitHub Desktop.

Select an option

Save serhiosipatron/c357a6f0939678e9f084244aa14695c8 to your computer and use it in GitHub Desktop.
var PORT = process.env.PORT || 8000;
const express = require('express');
const axios = require('axios');
PRODUCT_OPTIONS_ENUM = { COLOR_TITLE: { EN: 'Color' }; // this is more complex object at live
app.post('/product-update', function (req, res, next) {
const filterByName = (name) => {
return (item) => {
return item.name === name;
}
};
const getTags = (data,attr) => {
return data
.filter(filterByName(attr))
.map(i => i.values)
.reduce((acc, item) => acc.concat(item),[])
.map( i => attr.toLowerCase() + '-' + i)
};
const tags = getTags(req.body.options,PRODUCT_OPTIONS_ENUM.COLOR_TITLE.EN);
axios({
method: 'put',
headers : {
"Authorization" : auth
},
url: `https://${username}:${password}@yourshop.myshopify.com/admin/products/${req.body.id}.json`,
data: {
"product": {
"id": req.body.id,
tags: tags
}
}
})
.then(result => res.json(result.data))
.catch(err => res.status(400).json(err));
});
app.listen(PORT, function() {
console.log("App is running on port " + PORT);
});
@serhiosipatron
Copy link
Copy Markdown
Author

simplifyed version of webhooks update flow in shopify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment