'InvalidRedirect' Error with API Requests

  1. What do you want to achieve? Keep it simple and clear!
    I want to consistently fetch API data without encountering the “HttpError: InvalidRedirect” error.

  2. What is the issue? Include screenshots / videos if possible!
    Sometimes the API request works fine, but other times it fails with “HttpError: InvalidRedirect”.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

  4. I tried adding retry logic, checking the URL, and using pcall to handle errors. I also checked the Developer Hub for API documentation but didn’t find a clear solution.

The script fetches game data from the RoProxy API. It works fine most of the time, but occasionally triggers an “InvalidRedirect” error, preventing the request from completing. I’ve tried adding retry logic, but the issue still occurs sometimes.

Script:

-- -- ServerScript

local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getEventOne = ReplicatedStorage:WaitForChild("FetchDifferentGamesOne(1)")
local setEventOne = ReplicatedStorage:WaitForChild("FetchDifferentGames(1)")

-- Function to safely perform HTTP requests, retrying in case of invalid redirects
local function safeGetAsync(url)
    local success, response = pcall(function()
        return HttpService:GetAsync(url)
    end)

    if success then
        return response
    else
        -- Handle failed request or invalid redirect
        warn("Failed to fetch data from URL: " .. url .. ". Error: " .. response)
        return nil
    end
end

-- Function to get Place Info from the API (via RoProxy)
local function getPlaceInfo(placeId)
    if not tonumber(placeId) then
        return nil
    end

    -- Request the place info from RoProxy API
    local url = "https://apis.roproxy.com/universes/v1/places/" .. placeId .. "/universe"
    local response = safeGetAsync(url)

    if response then
        -- Decode the response and extract needed data
        local data = HttpService:JSONDecode(response)
        local universeId = data["universeId"]
        local placeName = game:GetService("MarketplaceService"):GetProductInfo(placeId).Name
        return {placeName, universeId}
    else
        -- Handle failed request or invalid redirect
        getEventOne:Fire(controllingData)

        -- Reset placeId to trigger a retry via setEventOne
        placeId = nil
        setEventOne.Event:Connect(function(gameID)
            placeId = gameID
            getPlaceInfo(placeId)  -- Retry after receiving the new game ID
        end)

        -- Wait until a valid placeId is received
        while placeId == nil do
            wait(0.01)
        end
    end
end

1 Like

InvalidRedirect as a HTTP error means you’re encountering a 301 or 302 status code from RoProxy (which are redirect codes), but the redirect URL is invalid for whatever reason.

Redirection is a concept where you go to a site, and it tells the HTTP client, no, go here instead, and it follows it until it doesn’t hit a 301/302.

This is not an issue you can fix directly as its likely an issue with the server providing roproxy.

i dont know how to fix it.
sorry.

It works perfectly fine on Studio for me as well, it’s just on the Roblox platform when I start encountering issues.

I’m also getting the error. Is this a bug that will be fixed soon?

1 Like

It’s been happening to me as well I just implemented a queue system that repeats the requests until they go through. Whenever I get the “Invalid Redirect” error it usually repeats for a minute until the request actually goes through.