Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Re: CORS error for fetching stock price

3630 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Chris_Finck
6 - Interface Innovator
6 - Interface Innovator

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!");

11 Replies 11

It’s spotty. Sometimes it works. Sometimes not. Can I see your code?

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);