// scr/app/api/getSnipcartProducts/page.js
import axios from ‘axios’;
const nodeBtoa = (b) => Buffer.from(b).toString(‘base64’);
export const base64encode = typeof btoa !== ‘undefined’ ? btoa : nodeBtoa;
module.exports = async (req, res) => {
const secret = ${process.env.SNIPCART_API_SECRET_KEY}
;
const products = (
await axios.get(‘https://app.snipcart.com/api/products’, {
headers: {
Authorization: Basic ${nodeBtoa(secret)}
,
Accept: ‘application/json’
}
})
).data;
var snipitems = [];
products &&
products.items.forEach((element) => {
var feature = {
id: element.userDefinedId,
stock: element.stock || 0
};
snipitems.push(feature);
});
return res.json(snipitems);
};