Created
August 19, 2022 19:14
-
-
Save procarrera/114781de59c97d4e9576a0ce1bfc91ad to your computer and use it in GitHub Desktop.
Shopify Get Product JSON by ID
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
const fetchProductJSON = async (product_id) => { | |
const id = parseInt(product_id) | |
const since_id = id - 1 | |
try { | |
const baseURL = | |
"https://powerkitchen.ca/products.json?since_id=" + since_id; | |
const res = await fetch(baseURL); | |
const data = await res.json(); | |
const product = data.products.filter(p=>p.id == id)[0] | |
return product; | |
} catch (e) { | |
console.error(e); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment