ash-jc-allen / laravel-exchange-rates

A Laravel wrapper package for interacting with the exchangeratesapi.io API.
MIT License
449 stars 49 forks source link

API Error #133

Closed MuhammadElmahi closed 1 year ago

MuhammadElmahi commented 1 year ago

Hello, When trying to get the output it gives me this api error

Client error: GET http://api.exchangeratesapi.io/v1//latest?access_key=%7Bce7e75f2bbb3079c0aeeca8bb64816e5%7D&base=USD&symbols=SAR resulted in a 401 Unauthorized response: {"error":{"code":"invalid_access_key","message":"You have not supplied a valid API Access Key. [Technical Support: suppo (truncated...) (View: /home/user/website.com/resources/views/home.blade.php) .

I wrote the API correctly from exchangeratesapi.io, And for implementation I just Added this code to .env folder EXCHANGE_RATES_API_KEY={my-api}

ash-jc-allen commented 1 year ago

Hey @MuhammadElmahi! Sorry that you're having issues with the package. Please could you show me the code you're using that's giving this error? And could you please also let me know which version of the package you're using? 🙂

jlevers commented 1 year ago

Hey @ash-jc-allen – thanks for the great library!

I'm running into this too – I'm on v7.0.1. This is the code that's failing:

use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;

$ratesProvider = app(ExchangeRate::class);
$rates = $ratesProvider->exchangeRate('USD', 'GBP');
// HTTP request returned status code 401:
// {"error":{"code":"invalid_access_key","message":"You have not supplied a valid API Access Key. [Technical Support: suppo (truncated...).
ash-jc-allen commented 1 year ago

Hey @jlevers! Sorry that you're having the same issue. Please can you let me know which API service you're using so I can check it out 🙂

jlevers commented 1 year ago

I was using exchangeratesapi.io. I'm on the free tier, in case that's relevant.

ash-jc-allen commented 1 year ago

Thanks for the extra info @jlevers, I'll try and take a look at this soon. Just to double-check, please can you confirm that you have the correct API key set in the .env file? 🙂

jlevers commented 1 year ago

Yep, double-checked the key and it's correct...but I just tested this again this morning and got a different error:

{
    "success":false,
    "error": {
        "code":105,
        "type":"base_currency_access_restricted"
    }
}

This one makes a bit more sense, as apparently exchangeratesapi.io doesn't allow you to use all base currencies on the free plan (which I didn't realize till now). Not sure why I was getting the other error before...sorry for the false alarm.

ash-jc-allen commented 1 year ago

Hey! It's no problem at all. I think all 3 of the APIs supported by this package are now all managed by the same company.

They seem to have recently put the exchangerate.host API behind a paywall and require an API key to be passed in every request now too. So this has broken the driver for that API service (I'm currently fixing it).

And I think they've recently been tinkering with some of the features and plans. I've seen some reports from people on Twitter that had the same errors the other day.

I'm going to close this issue for the time being because I think the problem was with the API and it should hopefully be working again now. But if this is still affecting you (or anyone else), please let me know and I'll take a look 😄