HTTP 426 (Upgrade Required)

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)

I don’t know why but this results
Unable to cast value to std::string

local http = game:GetService("HttpService")
local key = "many numbers and letters"
local search = input

local request = ("https://newsapi.org/v2/everything?q=" .. search .. "&apiKey=" .. key .."&from=2020-11-10&sortBy=published")

input is the search bar gui thing.

{“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.”}

Can you send the full script minus the API key?

That doesn’t help in any way.

If you actually understood what he was doing you’d know he has a key and search system.

1 Like

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)

I dont realy know where is the problem

What is “input”? Can you show the line of code from the script? I’m 99% sure I know why it errors that but I need to confirm

SearchRemote:FireServer(script.Parent.Parent.SearchBox.Text)

which is the search query on a surfacegui.
From a external localscript.
Is input a reserved keyword??

I am going to have to be afk for 25 minutes :confused:
I think that there is a large change that this will work lateron, as it worked at first.

I will read the new messages in 25 minutes.

Is it possibly that your request is wrapped in brackets (if your going to do this write tostring in front)?

If you write tostring in front of the brackets aka

local request = tostring("https://newsapi.org/v2/everything?q=" .. search .. "&apiKey=" .. key .."&from=2020-11-10&sortBy=published")

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:

local response = http:RequestAsync(request)
1 Like

I was about to point this out as well. Also, @Mishaho what happens if the textbox is blank?

(Also, they’re using RequestAsync, you linked GetAsync)

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.

1 Like

Thank you for pointing this out,

but why did it work at first?

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.

The website is not very clear about it. This could be the reason tho.

but no 200 requests yet:

image

1 Like

I tried this exact code on Studio:

local hs = game:GetService("HttpService")
print(hs:GetAsync("https://newsapi.org/v2/everything?q=bitcoin&apiKey=XXXXXXXX"))

Would you mind trying it to see if it outputs anything? Mine successfully ran.

1 Like

That results the expected output…
wait what

Sorry for the deleted post, had accidentally put my API key in it.
May you send your code?

Apparently, removing the &from=2020-11-10&sortBy=published worked.

1 Like

You could leave it at &from=2020-11-10 published is not a value that can be used for sortBy image

1 Like