local api = {}
local Config = require(script.Parent.Parent.Config)
function api.sendDataToServer(endpoint, data)
local url = Config.APIUrl .. endpoint;
local success, response = pcall(function()
return game.HttpService:PostAsync(url, "POST", data, true)
end)
if success then
print("Data sent successfully:", response)
else
warn("Error sending data:", response)
end
end
function api.getStatus()
local endpoint = "/status"
local url = Config.APIUrl .. endpoint
local success, response = pcall(function()
return game.HttpService:GetAsync(url, true)
end)
if success then
print("Status retrieved successfully:", response)
return response
else
warn("Error retrieving status:", response)
return nil
end
end
return api
Are you sure the data parameter in api.sendDataToServer() is an HttpContentType Type? The third parameter in PostAsync requires this Enumerator object, not a string value. If the data parameter is correct, maybe you should use Enum.HttpContentType[data]
Error sending data: {"timestamp":1707021984,"userId":629627855,"reason":""} is not a valid member of "Enum.HttpContentType" - Server - Api:15 23:46:26.607 Infinite yield possible on 'cloud_218303841.Model.GUIs.SignalGUI.Scripts:WaitForChild("Mode")
local url = Config.APIUrl .. endpoint;
local success, response = pcall(function()
return game.HttpService:PostAsync(url, "POST", Enum.HttpContentType[data], true)
end)
if success then
print("Data sent successfully:", response)
else
warn("Error sending data:", response)
end
end
Oh now I see the problem. You accidentally swapped the "POST" and the data arguments together. Data is supposed to be the 2nd argument. However, I don’t see that POST is a valid item in HttpContentType. You should change that.
Think i might be doing this wrong its 12 AM for me
Error sending data: {“timestamp”:1707022315,“userId”:629627855,“reason”:“test”} is not a valid member of “Enum.HttpContentType”
function api.sendDataToServer(endpoint, data)
local url = Config.APIUrl .. endpoint;
local success, response = pcall(function()
return game.HttpService:PostAsync(url, Enum.HttpContentType[data], true)
end)
if success then
print("Data sent successfully:", response)
else
warn("Error sending data:", response)
end
end
My first response in the topic was wrong. You should instead do:
return game.HttpService:PostAsync(url, data, Enum.HttpContentType.ApplicationJson, true) -- ApplicationJson is the default value, but you can change it.