Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jun 05, 2020 08:19 AM
I am using a script to fetch stock prices from https://financialmodelingprep.com/api/v3/quote-short/?{stock}?apikey=*
I run it and the CORS error pops up saying it is unable to fetch the data.
Then sometimes Ill click it and it’ll fetch but return the price undefined…
Any workaround to having this work a bit better? Here is my code if anyone is curious
output.markdown ("# Updating stock prices");
let table = base.getTable (“Stocks”),
records = await table.selectRecordsAsync ();
await Promise.all (
records.records.map (async record => {
let stock = record.getCellValue ("Ticker");
if (! stock) {
output.text ("Can't update the price of stock with no name");
return;
}
output.text (`Updating price of ${stock}...`);
// make request
var requestResult = await fetch (
`https://financialmodelingprep.com/api/v3/quote-short/${stock}?apikey=*`
).then (r => r.json ());
// print fetched data
output.markdown (`${stock}'s price right now is: **$${requestResult.price}**`)
// update record in table
return await table.updateRecordAsync (record, {
"CSP": requestResult.price,
"CSP Date": new Date ()
});
})
);
output.markdown ("# Done!");
Jun 23, 2020 08:02 PM
It’s spotty. Sometimes it works. Sometimes not. Can I see your code?
Jun 23, 2020 08:12 PM
I was just testing:
const response = await fetch('https://financialmodelingprep.com/api/v3/quote-short/AAPL?apikey=<MY API KEY>');
const json = await response.json();
output.inspect(json);