Struggling with this API. It works on postman - expected steps:
1- User completes chat command /user [id].
2- Script calls the API and passes [id].
3- API search DB for users with that id.
4- API passes back the username of that user and prints it into the chat.
I imagine this code is horrific and totally wrong but I am very new to Lua and FiveM code. Here is the error code.
FIVEM ERROR
[ script:TestingPOST] 2
[ script:TestingPOST] table: 000001ADC3990530
[ script:TestingPOST] 2
[ script:TestingPOST] nil
[ script:TestingPOST] SCRIPT ERROR: @TestingPOST/webhook_s.lua:16: attempt to index a nil value (local 'data')
I would really appreciate some help! :)
I have removed the API link and auth token
RegisterCommand("user", function(source, args, rawCommand)
local query = string.sub(rawCommand, 6)
print(source)
print(args)
print(query)
PerformHttpRequest('https://MYAPP.bubbleapps.io/version-test/api/1.1/wf/userdata',
function(err, text, header)
local data = json.decode(text)
TriggerClientEvent("chat:addMessage", source, {
args {
string.format("Display name is %s", data.response.displayname )
}
})
end, 'POST',
json.encode({userid = query}), {["Authorization"] = 'TOKEN'})
end)