HTTP request never succeeds

Hello,

I am trying to make a billboard that shows catalog items. I have seen posts using the Roblox API to do this. I tried to do this on my own, but I have very little knowledge of HTTPService. Here’s the script:

local TOP30HATSBILLBOARD = workspace:WaitForChild("ShowcaseTop30Hats"):WaitForChild("Top30Hats")

local HTTP = game:GetService("HttpService")

local JSONDecode = HTTP.JSONDecode

local GET = HTTP.GetAsync

local url = "https://catalog.roproxy.com/v1/search/items/details?Category=3&MaxPrice=1000"
local function getTop30Hats()
	local success,result = pcall(GET,HTTP,url)
	if success and result and result.Success then
		print("Success!")
		print(result)
		--local result2
		local successdecode,resultDecode = pcall(JSONDecode,HTTP,result)
		if successdecode and resultDecode then
			for _,info in next,resultDecode.Data do
				print("Successfully loaded information..")
				for i = 1, #resultDecode do
					local hatImage = Instance.new("ImageLabel",TOP30HATSBILLBOARD)
					hatImage.Size = UDim2.new(0,225,0,200)
					hatImage.Image = "rbxthumb://type=Asset&id=" .. info.productId
					hatImage.BackgroundTransparency = 1
					local hatNameAndPrice = Instance.new("TextLabel",hatImage)
					hatNameAndPrice.Size = UDim2.new(0,200,0,50)
					hatNameAndPrice.TextScaled = true
					hatNameAndPrice.Position = UDim2.new(0,15,0,210)
					hatNameAndPrice.BackgroundTransparency = 1
					hatNameAndPrice.Font = Enum.Font
					hatNameAndPrice.Font = Enum.Font.Roboto
					hatNameAndPrice.FontFace.Bold = true
					hatNameAndPrice.TextColor = BrickColor.Gray()
					hatNameAndPrice.Text = info.name .. " $" .. info.price
					print("Success!")
				end
			end
		else
			warn("Error happened decoding!")
			end
	else
		warn("Error occured!")
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		getTop30Hats()
	end)
end)

Any help is appreciated!
Note: If the error is from the proxy itself, then give me a good proxy to use.

1 Like

good

charrrrrrrrrrrrrrrrrrrrrrr

2 Likes

Hey there!

There’s a couple things I’ve noticed with the provided code.

  1. The GET function is never being called, it should be GET(url)
  2. The JSONDecode is not called correctly. It should be JSONDecode(HTTP, result.Body)
  3. The for loop that creates the hatImage and hatNameAndPrice objs should be using #info instead of #resultDecode, since resultDecode is an obj that contains a Data array.

I’ve made changes that should work.

My Approach

local TOP30HATSBILLBOARD = workspace:WaitForChild("ShowcaseTop30Hats"):WaitForChild("Top30Hats")

local HTTP = game:GetService("HttpService")

local JSONDecode = HTTP.JSONDecode

local GET = HTTP.GetAsync

local url = "https://search.roblox.com/v1/catalog/items?category=3&maxPrice=1000&sortType=1&creatorTargetId=0&minPrice=0"

local function getTop30Hats()
    local success, result = pcall(GET, HTTP, url)
    if success and result.Success then
        print("Success!")
        local successDecode, resultDecode = pcall(JSONDecode, HTTP, result.Body)
        if successDecode and resultDecode then
            for _, info in ipairs(resultDecode.data) do
                print("Successfully loaded information..")
                local hatImage = Instance.new("ImageLabel", TOP30HATSBILLBOARD)
                hatImage.Size = UDim2.new(0, 225, 0, 200)
                hatImage.Image = "rbxthumb://type=Asset&id=" .. info.id .. "&w=420&h=420"
                hatImage.BackgroundTransparency = 1
                local hatNameAndPrice = Instance.new("TextLabel", hatImage)
                hatNameAndPrice.Size = UDim2.new(0, 200, 0, 50)
                hatNameAndPrice.TextScaled = true
                hatNameAndPrice.Position = UDim2.new(0, 15, 0, 210)
                hatNameAndPrice.BackgroundTransparency = 1
                hatNameAndPrice.Font = Enum.Font.Roboto
                hatNameAndPrice.FontSize = Enum.FontSize.Size24
                hatNameAndPrice.FontWeight = Enum.FontWeight.Bold
                hatNameAndPrice.TextColor3 = Color3.fromRGB(255, 255, 255)
                hatNameAndPrice.Text = info.name .. " $" .. info.priceInRobux
                print("Success!")
            end
        else
            warn("Error happened decoding!")
        end
    else
        warn("Error occurred!")
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        getTop30Hats()
    end)
end)

An error still occured…
image_2023-03-03_182354734
I think its because you arent using a proxy…
I tried it with a proxy… still didn’t work.

1 Like

Yeah, I was testing using a direct connection and a workaround. Implement the proxy you’re using, and let me know what it outputs.

1 Like

It didnt work… still errored the same thing

1 Like

Let’s try debugging some things.

Instead of warn("Error occurred!" change this to:

warn(success);
warn(result);
1 Like

I got this in the console:
image_2023-03-03_183305464
When I put the link in my browser, it redirected me to the roblox error page?

1 Like

Give this a try

local TOP30HATSBILLBOARD = workspace:WaitForChild("ShowcaseTop30Hats"):WaitForChild("Top30Hats")

local HTTP = game:GetService("HttpService")

local JSONDecode = HTTP.JSONDecode

local url = "https://search.roblox.com/v1/catalog/items?category=3&maxPrice=1000&sortType=1&creatorTargetId=0&minPrice=0"

local function getTop30Hats()
    local success, result = pcall(function()
        return HTTP:RequestAsync({
            Url = url,
            Method = "GET",
            Headers = {
                ["User-Agent"] = "Roblox/WinInet",
                ["Accept-Encoding"] = "gzip",
            },
            AutomaticDecompression = Enum.AutomaticSize.Gzip,
            FollowRedirects = true,
        })
    end)
    if success and result.Success then
        print("Success!")
        local successDecode, resultDecode = pcall(JSONDecode, HTTP, result.Body)
        if successDecode and resultDecode then
            for _, info in ipairs(resultDecode.data) do
                print("Successfully loaded information..")
                local hatImage = Instance.new("ImageLabel", TOP30HATSBILLBOARD)
                hatImage.Size = UDim2.new(0, 225, 0, 200)
                hatImage.Image = "rbxthumb://type=Asset&id=" .. info.id .. "&w=420&h=420"
                hatImage.BackgroundTransparency = 1
                local hatNameAndPrice = Instance.new("TextLabel", hatImage)
                hatNameAndPrice.Size = UDim2.new(0, 200, 0, 50)
                hatNameAndPrice.TextScaled = true
                hatNameAndPrice.Position = UDim2.new(0, 15, 0, 210)
                hatNameAndPrice.BackgroundTransparency = 1
                hatNameAndPrice.Font = Enum.Font.Roboto
                hatNameAndPrice.FontSize = Enum.FontSize.Size24
                hatNameAndPrice.FontWeight = Enum.FontWeight.Bold
                hatNameAndPrice.TextColor3 = Color3.fromRGB(255, 255, 255)
                hatNameAndPrice.Text = info.name .. " $" .. info.priceInRobux
                print("Success!")
            end
        else
            warn("Error happened decoding!")
        end
    else
        warn(success);
        warn(result);
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        getTop30Hats()
    end)
end)

The console said that Gzip is not a valid member of AutomaticSize

Change
local JSONDecode = HTTP.JSONDecode
to
local JSONDecode = HTTP:JSONDecode()

It errors with Argument 1 missing or nil

Let me recreate this. One moment.

Is this your hosted proxy? Something doesn’t seem right.

No, im using someone else’s proxy…