HTTP 400 Please Help

Hello guys. i made a script that sends a HttpGet but for some reason it keeps saying HTTP 400. this is my code. is this because of the magic characters?

local HttpService = game:GetService("HttpService")
local TextService = game:GetService("TextService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("WaterBotMessage")
Remote.OnServerEvent:Connect(function(Player,Message)
	if type(Message) == "string" and #Message <= (1997-(#Player.Name-#Player.DisplayName)) then
		local FilteredString = nil
		local Success,Error = pcall(function()
			local FilteredInstance = TextService:FilterStringAsync(Message,Player.UserId)
			FilteredString = FilteredInstance:GetNonChatStringForUserAsync(Player.UserId):gsub("#","%%")
		end)
		if Success then
			local PlayerInformation = Player.Name.." ("..Player.DisplayName..")"
			local JSONEncoded = "http://ihidtheapilink?JSONEncoded={\"embeds\":[{\"title\":"..FilteredString..",\"description\":"..PlayerInformation.."}]}"
			local POSTSuccess,POSTError = pcall(function()
				print(JSONEncoded)
				HttpService:GetAsync(JSONEncoded)
			end)
			if POSTError then
				print(POSTError)
			end
		end
	end
end)

First off, you should hide your API link or anyone else who sees the code can use it.

HTTP 400 Status Code means β€œBad Request”.

In other words, the request you sent to the API endpoint is invalid in someway. It could be wrongly formatted request message framing, or invalid request syntax. Check that you’re sending the request path parameters correctly.

yes its correct but the query parameter has characters like β€œ{” and β€œ:”. im trying to find a solution without it erroring

Try creating a separate table for the request with the sufficient request parameters and then define that table inside the query parameters.

then i cant set the variable on the other side, the ?JSONEncoded variable was to set the JSONEncoded on the api to a JSON then send it to a discord webhook.

You…lost me.

If you made this API endpoint, I suggest making the request parameters a part of the request body instead of using query parameters. It would make things much easier.

It said it could be only changed with query parameters.

Sorry for the late reply. Can I have a link to the API reference from your screenshot?

Nevermind I managed to do it with content body.

1 Like

You need to format the JSON correct and you should be using HttpService:JSONEncode.

local JSONContent = HttpService:JSONEncode({
    ["embeds"] = {
        {
            ["title"] = FilteredString,
            ["description"] = PlayerInformation
        }
    }
})

My string and jsonencode is the same.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.