Last active
July 24, 2020 11:43
-
-
Save serhiosipatron/c357a6f0939678e9f084244aa14695c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simplifyed version of webhooks update flow in shopify