I’m trying to retrieve data from RapidAPI for cryptocurrencies using Redux, but I keep receiving a 401 unauthorized error in the console. It seems that my request is being sent, but the API responds with an unauthorized message. I suspect there might be a problem with my headers or the API key.
Yeah, that typo’s part of the problem, but there’s another issue. You’re passing headers through buildRequest but fetchBaseQuery doesn’t know about them since you’re only setting the baseUrl. You need to put the headers in your base query config instead.
also check if ur rapidapi subscription expired - i got the same 401 errors last week when my free tier hit the request limit. double-check ur using /coins not /markets for the coinranking api endpoint.
Found your problem right away. You’ve got a typo in buildRequest - you wrote Headers with a capital H instead of headers. That’s why your auth headers aren’t getting sent and you’re getting the 401 error. Change Headers: headers to headers: headers and you should be good. Also double-check you actually replaced ‘your-api-key’ with your real key from the RapidAPI dashboard. I made this exact same mistake last month and wasted hours debugging before I caught the capitalization error. Fix that typo and your requests will authenticate properly.