Currency converter

Hello, I want to get currency rates value in my table. I make table KURS EURO:
image

I ask AI Assistant but don’t know how to implement that code:

Please help me to make currency rates in columns KUPNO (means buy), SPRZEDAŻ (means sell) and SREDNI (means average exchange rate) with API: http://api.nbp.pl/api/ to get exchange rates Euro to Polish Zloty.
To fetch currency exchange rates from the NBP API and create columns for buy (KUPNO), sell (SPRZEDAŻ), and average (SREDNI) exchange rates, you can define a function called fetch_currency_rates that takes a date as input and returns a dictionary containing the exchange rates. Then, you can use this function to create the new columns in your data table.

Here's the code for the fetch_currency_rates function:

import requests

def fetch_currency_rates(date):
    # Format the date in the required format for the API
    formatted_date = date.strftime('%Y-%m-%d')
    
    # Make a request to the API to fetch the exchange rates
    url = f'http://api.nbp.pl/api/exchangerates/rates/A/EUR/{formatted_date}/'
    response = requests.get(url)
    data = response.json()
    
    # Extract the exchange rates
    rates = data['rates'][0]
    buy_rate = rates['bid']
    sell_rate = rates['ask']
    average_rate = rates['mid']
    
    return {
        'KUPNO': buy_rate,
        'SPRZEDAŻ': sell_rate,
        'SREDNI': average_rate
    }

I try to add that in formula field but get error:

Can somebody help me with that?
Regards.

There is an experimental REQUEST function that can be enabled for self-hosted instances of Grist (with a few caveats) with an interface similar to requests.get.

You can see more information in this thread and how to enable the function once self-hosted in this post.

Hi, I add that this way in Unraid:


It’s OK?

Yes, that Unraid setting looks ok. Also make sure your version of Grist is reasonably up to date.

Thanks, but nothing happen when I try that formula in self hosted grist.