0

I'm in CS50w, lecture 5 (JavaScript)

I have a problem in lecture 5(JavaScript) time: 1:34:40.

Brian said using http://api.exchangeratesapi.io/latest?base=USD in code below:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Curency Exchange</title>
        <script>
            document.addEventListener('DOMContentLoaded', function() {

                fetch('http://api.exchangeratesapi.io/latest?base=USD')
                .then(Response => Response.json())
                .then(data => {
                    console.log(data);
                });
            });
        </script>
    </head>
    <body>
         
    </body>
</html>

But returns error!

enter image description here

Then I get tried exploring the link above, so that redirected to https://apilayer.com/. I have tried signing up and signing in Exchange Rates Data API Currency, So this gets me an API key.

But I'm not succeed get results Brian said in lecture mentioned above.

Helps are appreciated.

3 Answers 3

1

You want to check out the documentation for that api. It can be found here.

According to the documentation, after you get your API Key, you add it to the url as a parameter as such:

https://api.exchangeratesapi.io/v1/latest
? access_key = API_KEY

where API_KEY is your key. You can still use the base parameter too, which would look like:

https://api.exchangeratesapi.io/v1/latest
? access_key = API_KEY
& base = USD
2
  • I have tried fetch('https://api.exchangeratesapi.io/v1/latest?access_key=cjUP2T7CmZ3DFUWWRCWOcA2lQekDDogW&base=USD') and still revived error: Object { code: "invalid_access_key", message: "You have not supplied a valid API Access Key." }
    – parmer_110
    Commented Mar 4, 2023 at 18:36
  • Still I have "invalid_access_key" error in using https://api.exchangeratesapi.io/v1/latest?access_key=cjUP2T7CmZ3DFUWWRCWOcA2lQekDDogW But What is the problem?
    – parmer_110
    Commented Mar 4, 2023 at 19:02
0

I have found out the structure of https://api.exchangeratesapi.iohad changed.

  1. Auto redirecting to the https://apilayer.com/
  2. The API_KEY now is apikey

https://api.apilayer.com/exchangerates_data/latest?apikey=cjUP2T7CmZ3DFUWWRCWOcA2lQekDDogW&base=USD

enter image description here

Reff: https://apilayer.com/

0

This api is a drop-in replacement https://api.exchangerate.host/latest?base=USD'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .