Currency conversion

Is there a way to get up to date currency exchange rates in a snipett, specifically GBP to USD

Hi @tonyd you would need to find an online service (API) that can send the live currency exchange data. Once that's available, you can load that data in Text Blaze using the urlload command. The following documentation page shows how to use it:

I got this from CoPilot:
GBP to USD: {web.get("https://api.exchangerate.host/latest?base=GBP&symbols=USD",headers:{}, path:"rates.USD")}

So tried this:
{urlload: https://api.exchangerate.host/latest?base=GBP&symbols=USD,headers:{},path:"rates.USD"}

but it doesn't work. Any ideas?

It is trying to contact api.exchangerate.host which looks like this service https://exchangerate.host/

You will need to get an API key from the respective service you are trying to use. Note that the service will enforce its own terms (such as X number of free monthly/daily queries).

ok. I now have an API key

Hi @tonyd the website would give you the appropriate Headers in which to use the API key. For example, a snippet like this may work:

{urlload: https://api.exchangerate.host/latest?base=GBP&symbols=USD; headers=Authorization: Bearer {=KEY}; done=(res) -> ["response": fromjson(res), "isloading": no]; start=() -> ["isloading": yes]}
{if: isloading}Loading...{else}Response: {=response}{endif}

Thanks. It has accepted my API key but get 'invalid headers' and 'unknown name "isloading"

This is the documentation for live data;

Based on the documentation, a snippet like the following may work:

{urlload: https://api.exchangerate.host/live?source=GBP&currencies=USD&access_key=XX; done=(res) -> ["response": fromjson(res), "isloading": no]; start=() -> ["isloading": yes]}
{if: isloading}Loading...{else}Response: {=response}{endif}

You can replace XX with your key.

Great, that worked: Thank you so much.

Response: ["success": yes, "terms": "Terms & Conditions | currencylayer API", "privacy": "Privacy Policy | currencylayer API", "timestamp": 1769419504, "source": "GBP", "quotes": ["GBPUSD": 1.366596]]

Is there a way I can extract the 1.366596 element so I can use that in a snippet? If it helps, that number will, I believe, always start with 1.3

If extracting the rate element is too complex I can just use the whole response in the snippet within a {note} and enter it manually

Hi @tonyd try:
{=response["quotes"]["GBPUSD"]}

Hi Dan, thanks. That worked. Can I give that a name so I can use it in the snippet. Also I've tried putting the main formula in a {note} but still see it in the output.

Sorry forget the {note} bit. I put {endnote} in the wrong place.

As for naming it, sure, try this:
{exchange=response["quotes"]["GBPUSD"]}

That stopped the response working I'm afraid

It creates a variable, but doesn't insert it. To insert it, use this:
{exchange=response["quotes"]["GBPUSD"]}
{=exchange}

Got it, thanks again.