{“status”:“error”,“code”:“apiKeyInvalid”,“message”:“Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key.”}
The entire system works in 2 server scripts and one local script , but I will sent the crucial part.
local SearchRemote = game.ReplicatedStorage.Search
local UpdateClients = game.ReplicatedStorage.Update
local HideRemote = game.ReplicatedStorage.Hide
local ShowRemote = game.ReplicatedStorage.Show
function OnRequest(plr, input)
ShowRemote:FireAllClients()
print(plr.Name .. " requested.")
local http = game:GetService("HttpService")
local key = "i hided the key! but it is 100% correct on my client."
local search = input
local request = ("https://newsapi.org/v2/everything?q=" .. search .. "&apiKey=" .. key .."&from=2020-11-10&sortBy=published")
local response = http:RequestAsync(
{
Url = request,
Method = "GET"
}
)
local result = http:JSONDecode(response)
UpdateClients:FireAllClients(
"Search Query",
result.articles[1].title,
result.articles[1].url,
result.articles[1].description,
result.articles[2].title,
result.articles[2].url,
result.articles[2].description,
result.articles[3].title,
result.articles[3].url,
result.articles[3].description,
result.articles[4].title,
result.articles[4].url,
result.articles[4].description,
result.articles[5].title,
result.articles[5].url,
result.articles[5].description
)
clr() -- This will happen 20 sec after results were sent.
end
function clr()
wait(20)
HideRemote:FireAllClients()
end
SearchRemote.OnServerEvent:Connect(OnRequest)
That might be the reason why it flagged but it will eliminate the problem.
The more likely issue:
However according to the API documentation you don’t need to set the method so the second cause of your issue might be that you need to do response as follows instead of how you’ve done it:
This is most likely a Roblox or newsapi issue. The issue is that newsapi requires a protocol that Roblox does not support. According to this post Does Roblox support http/2 protocol? - #8 by Corecii Roblox only supports HTTP 1.1 and according to keycdn’s HTTP 2 test newsapi only supports HTTP 2.
Normally an "upgrade" header would be sent which would mention the expected protocol according to MDN but Roblox probably doesn’t return it. Unless there is a way to change the supported protocols on newsapi, you would have to use a proxy server that upgrades Roblox’s request’s to the protocol newsapi supports, or you could make a feature request to add HTTP 2 support.
It seems like the API you’re using is paid, and has a free trial of 200 requests per month. 426 Upgrade Required - HTTP Status Code Glossary - WebFX says that you need to “upgrade”, and by upgrade, the website probably means to pay them.
The error doesn’t come from your script neither does it come from Roblox - it comes from your plan that has probably expired.