Margaux, what you’re asking for is totally feasible and I did it for a client of mine. You either need a webhook to trigger the update or you need to schedule a cron job that runs every 10 minutes for example.
Here’s a piece of code I created for a client of mine:
const Webflow = require("webflow-api");
const axios = require("axios");
exports.updateGoldPrice = async (req, res) => {
class MainController {
async startUpdateLoop() {
const webflow = new Webflow({
token:
"xxxxxxxxxxx",
});
const collectionId = "xxxxxxxxxxx";
// await webflow.info();
// res.status(200).send('ok');
const itemsToBeUpdated = [
{
itemId: "xxxxxxxxxxx",
priceMultiplier: 1,
amountMultiplier: 1.3,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"691541853a7efa0d8f91551c3476d784",
},
},
{
itemId: "5e48413b08eef865954a1a97",
priceMultiplier: 2.5,
amountMultiplier: 1.22,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"f48d0db57800294c8a5116ab3c61dcd2",
},
},
{
itemId: "5e48413bbaff8f38eca5c259",
priceMultiplier: 5,
amountMultiplier: 1.19,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"fd437df14e612db644fbebfa669a43e7",
},
},
{
itemId: "5e48413b9065e7ae39113195",
priceMultiplier: 10,
amountMultiplier: 1.16,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"84c23c10087dd23ed527046c1d826631",
},
},
{
itemId: "5e48413bbaff8f6490a5c25a",
priceMultiplier: 20,
amountMultiplier: 1.14,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"b8e88d1118c1197b019d08384723c4fa",
},
},
{
itemId: "5e48413bbaff8f468fa5c258",
priceMultiplier: 31.1,
amountMultiplier: 1.08,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"8e9a6492fa6f13c7cfe017430cdcc817",
},
},
{
itemId: "5e48413b9065e7362a113197",
priceMultiplier: 50,
amountMultiplier: 1.08,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"b08c33004b72f7eff6ad4b5ace5870de",
},
},
{
itemId: "5e48413b353d45da09ad569d",
priceMultiplier: 100,
amountMultiplier: 1.07,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"c212e09747d385dcceda4f9a4f5e0a0c",
},
},
{
itemId: "5e48413b9ce5345e6464004c",
priceMultiplier: 250,
amountMultiplier: 1.07,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"f0861041781b418d29111f6284bbd83b",
},
},
{
itemId: "5e48413b9ce534230464004d",
priceMultiplier: 500,
amountMultiplier: 1.07,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"ac6acafb479ed8040e9aa16448f76547",
},
},
{
itemId: "5e48413b353d456b0fad569b",
priceMultiplier: 1000,
amountMultiplier: 1.07,
skuValuesObj: {
da3ae7e3305dbf6030e37ef9bb1d0c3c:
"a5da794b0edd143ceaa579efd2b245f8",
},
},
];
const updateGoldPrice = async () => {
const response = await axios.get(
"https://forex-data-feed.swissquote.com/public-quotes/bboquotes/instrument/XAU/EUR"
);
let currentSellPrice = response.data[0].spreadProfilePrices[0].ask;
currentSellPrice = (currentSellPrice / 31.1) * 100;
for (let i = 0, len=itemsToBeUpdated.length; i < len; i += 1) {
const e = itemsToBeUpdated[i];
webflow
.patchItem({
collectionId,
itemId: e.itemId,
fields: {
price: {
unit: "EUR",
value: Math.ceil(
currentSellPrice * e.priceMultiplier * e.amountMultiplier
),
},
product: "5e48413a9065e74de0113193",
"sku-values": e.skuValuesObj,
},
})
.then((item) => {
console.log(item);
}).catch (error) {
console.log(error);
};
}
};
await updateGoldPrice();
}
}
const updater = new MainController();
await updater.startUpdateLoop();
let message = "Started update";
return res.status(200).json(message);
};