Too many request

So i have an api that i need to send a lot of request to it like 1 request for every 1.5 s

so the api after some time break and says too many request but it not giving me the respons it just give me error the api it self have a break time in the respons but
image
so how do i get the retry after tho it giving me an error ? Thanks

If my assumption is correct, consider using pcalls

local success, result 

while not success do
  success, result = pcall(function() 
    -- whatever code you want here
  end)
  task.wait(1.5)
end

this is just a basic pcall loop that keeps going until it works, often used for datastores

1 Like

Use the retry_after parameter to respect the API limits so it stops dropping the requests:

local function makeRequest(...)
	--do things here
	--response is the API response in bytes
	local data = game.HttpService:JSONDecode(response) 
	if data.message and data.message == "The resource is being rate limited." then
		task.wait(data.retry_after)
		return makeRequest(...) --redo the request after the time has passed
	end
	--continue processing the request as normal and return the expected data
end
2 Likes

well i tried but it giving me anthor error " Can’t parse JSON" Thank you

There’s a chance the API normally wont return a JSON encoded dictionary(if the request is not rate limited), if that’s the case try adding a pcall to your logic:

local success, data = pcall(function()
	return game.HttpService:JSONDecode(response)
end)
if success and data.message and data.message == "The resource is being rate limited." then
	task.wait(data.retry_after)
	return makeRequest(...) --redo the request after the time has passed
end
--continue processing the request as normal and return the expected data
2 Likes

what if it is i mean that the problem it giving me an error so how could i even get the message or the retry_after? Thank you very much ;D

The error is JSON encoded, it’s not an actual coding error within your Roblox script. The pcall is checking if the API is returning a JSON or not without having to break/error your code. Depending on that it determines if you’re being rate limited or not(with a few more checks below).

1 Like