HTTP 426 (Upgrade Required)

That should work however GetAsync only returns the body and the solution to this error should be in the headers. Try running this and tell me the results

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"
    }
)
print(response.Headers)

dont forget it could be just a temporary problem

2 Likes

Try printing response.StatusMessage

My bad, both headers and status message work.

StatusMessage said this:

image

Oh then what does Headers say?

   ["cache-control"] = "no-cache",
    ["cf-cache-status"] = "DYNAMIC",
    ["cf-ray"] = "6000ce943aa6dbfb-LHR",
    ["cf-request-id"] = "06f45f70ab0000dbfbf439c000000001",
    ["connection"] = "keep-alive",
    ["content-length"] = "255",
    ["content-type"] = "application/json; charset=utf-8",
    ["date"] = "Fri, 11 Dec 2020 17:08:19 GMT",
    ["expect-ct"] = "max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"",
    ["expires"] = "-1",
    ["nel"] = "{"report_to":"cf-nel","max_age":604800}",
    ["pragma"] = "no-cache",
    ["report-to"] = "{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=KRNjQqQY4pJ9Vvu1FwmtNrim4YiJG6aS4wx%2F7WsQLVuFB8rpLhKPnP0gknqM0Z6mUVF2%2FsYtt%2Bnu6%2BqK3zE%2FZGQc14AOsy50V1MApQ%3D%3D"}],"group":"cf-nel","max_age":604800}",
    ["server"] = "cloudflare",
    ["set-cookie"] = "__cfduid=dfc0400dc014b7a1af4c88540e8eba2791607706499; expires=Sun, 10-Jan-21 17:08:19 GMT; path=/; domain=.newsapi.org; HttpOnly; SameSite=Lax",
    ["x-cached-result"] = "false"
  }
1 Like

so is it now fixed the problem is fixed?

Well looking at the response it gave you, its nothing to do with how the the news API itself (so nothing has changed on their end). But instead it looks like it might possibly be the formatting of your request, as it goes to the first endpoint and realises that your formatting is off for what it supports and it simply says “no” and responds back saying I don’t like your formatting.

Can we see the request you make (hiding your API key)?

2 Likes
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