Same code as before, just without indexing the data before decoding it…

AddEventHandler("playerConnecting", function(name, kickReason, deferrals)
	deferrals.defer()
	PerformHttpRequest("[url]", function(code, data, headers)
		if code == 200 then
			local data = json.decode(data)
			local results = data["results"][1]
			print(json.encode(results))
			
			deferrals.done("stop connecting for testing..")
		else
			deferrals.done("Whitelist Connection Issue. Please try again later .. [" .. code .. "]")
		end
	end, "GET", json.encode({}), {["Content-Type"] = "application/json", ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"})
end)

Same error as before:

Error running system event handling function for resource salrp-utils: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: whitelist_server.lua:6: attempt to index a nil value (field 'results')
stack traceback:
        whitelist_server.lua:6: in local 'userCallback'
        citizen:/scripting/lua/scheduler.lua:274: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:175: in function <citizen:/scripting/lua/scheduler.lua:174>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:174: in function <citizen:/scripting/lua/scheduler.lua:138>

You might wanna remove the URL?

I am just taking a look at the code for a second.

Contact me on discord so that doesn’t happen again.

Alright… after talking in Discord for a bit, we came to the conclusion it was PHP. I made the REST API use NodeJS and did the requests that way, updated my resource to use the new URL and it returned a table for the first print statement.

1 Like

Do you still have access to this resource? If so, is there a way you would be willing to share the resource (publicly or privately)?

I don’t have the resource itself, but the code above should work fine - although it was from two years ago so it may need some tweaking?

Alright.

Where was this issue/should I expect to encounter this?

From what I can remember, the issue was with PHP not returning the data I wanted properly. Since I don’t have any of the code for the API anymore, I really don’t know what was actually wrong.

Alright. I appreciate you replying!

1 Like