Created
April 3, 2018 21:17
-
-
Save typerory/9a271b3daa15a1e73011215c38b9f2be to your computer and use it in GitHub Desktop.
Pull from Zoho Inventory products to Firestore
This file contains 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
exports.updateItems = functions.database.ref('/update').onUpdate(event => { | |
return superagent | |
.get(zohoItemsRef + 'items?' + zohoToken + zohoOrg) | |
.query({ | |
authtoken: zohoToken, | |
organization_id: zohoOrg | |
}) | |
.set('cache-control', 'no-cache') | |
.then(res => { | |
res.body.items.forEach(function(item) { | |
if (item.status === 'active') { | |
var itemData = { | |
name: item.name, | |
description: item.description, | |
price: item.rate, | |
category: item.cf_product_category, | |
src: item.cf_src, | |
manufacturer: item.cf_iotymanufacturer, | |
model: item.cf_iotymodel, | |
createdTime: item.created_time, | |
lastModifiedTime: item.last_modified_time | |
} | |
if (item.cf_quick_pick) { | |
itemData.quickMenu = item.cf_quick_pick | |
} | |
if (item.cf_size) { | |
itemData.size = item.cf_size | |
} | |
itemRef.doc(item.item_id).set(itemData) | |
} | |
}) | |
return | |
}) | |
.catch(e => { | |
console.log(e) | |
return | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment