-
What do you want to achieve? I want to be able to send a request to an API and return results to use in my game
-
What is the issue? Everytime i run the code i get error 400 bad request (invalid api key)
-
What solutions have you tried so far? At first, I figured it’s because im missing the GetAsync X-Api-Key headers but when i added it, it still didnt work. So i looked for nearly every single topic about API keys on here and basically memorized the docs at this point on http service and API keys but i still couldn’t find a solution, I understood from the topics that http error 400 is something wrong in my part of how im writing the code. I’m sure the key i typed is correct because it’s copied directly from the dashboard
- Here is the Api Website
- Before you reply, notice this: Api requests settings are enabled in my game settings, HTTP requests are also enabled, the code is in a normal script not a local script and yes, I used a pcall but that won’t fix the issue.
Here is my code:
local httpService = game:GetService("HttpService")
local url = "https://api.api-ninjas.com/v1/facts"
local headers = {
["X-Api-Key"] = "Obviously can't reveal it, but its that one extremely amazingly long characters of the alphabet and is basically like OiskaoOIGSiodiJaOL"
}
local response
pcall(function()
response = httpService:RequestAsync({
Url = url,
Method = "GET",
Headers = headers,
})
end)
if response then
print(response)
end
Output:
{
["Body"] = "{"error": "Invalid API Key."}",
["Headers"] = ▶ {...}, --irrelevant stuff, some cache data
["StatusCode"] = 400,
["StatusMessage"] = "Bad Request",
["Success"] = false
}
Description of the Api key settings:
name X-Api-Key
Status active
Enable key yes
Access permissions → 1. Universe (im sure its the correct experience)
experience operations universe.place.write, universe:write
Security I wrote a correct IP address, for security reasons I cannot show
Expiration No expiration