HTTP 400 Bad Request for Webhook?

I am making a “form” system where users answer certain questions for an application of a position.

I’ve ran into an error within the function where I combine gotten answers into one ready-to-send package for the webhook. It seems to print HTTP 400 bad request.

Surprisingly it seems to work if I remove one of the fields as it combines perfectly and sends it correctly to the webhook, therefore it’s likely a problem in the way this is formatted. I would like to have 3, not 2 fields for this purpose. How can I fix this for that to be possible?

local function combineContent(plrName, answer1 , answer2, answer3)
	local embed = {
		embeds = {
			title = "An application has been submitted!",
			description = ("Application submitted by " ..plrName),
			color = tonumber(0x00A3FF),
			fields = {
				{
					name = "Why should we choose you?",
					value = answer1,
					inline =  true
				},
				{
					name = "Do you have any past experience?",
					value = answer2,
					inline =  true
				},
				{
					name = "How active are you?",
					value = answer3,
					inline =  true
				},
			}
		}
	}
	return embed
end

Try removing the comma if possible

Still doesn’t seem to work for some reason, I get the same error.

What webhook url are you trying to send it to?

It’s a Discord webhook that goes within a channel of a staff server.

Are you encoding it before sending it?

Yes, here’s my webhook-posting function, with the “data” variable being the returned result of the combineContent function.

local function PostApp(data)
	local newdata = httpserv:JSONEncode(data)
	httpserv:PostAsync(webhooklink, newdata)
end

That’s not a valid color. You dont use hex on embeds. You use decimal. For example, a bluish color would be 34749. You can google hex/rgb to decimal and convert your color.

That is a valid color.

tonumber converts it to normal digits

After some decoding I found your issue. You forgot an array in your webhook. This is how it should look like.

local function combineContent(plrName, answer1 , answer2, answer3)
	local embed = {
		embeds = {
			{
				title = "An application has been submitted!",
				description = "Application submitted by "..plrName,
				color = tonumber(0x00A3FF),
				fields = {
					{
						name = "Why should we choose you?",
						value = answer1,
						inline =  true
					},
					{
						name = "Do you have any past experience?",
						value = answer2,
						inline =  true
					},
					{
						name = "How active are you?",
						value = answer3,
						inline =  true
					},
				}
			}
		}
	}
	return embed
end

image

@valeristx This is the original poster.

Thank you very much, it’s odd how such a small mistake can stop an entire script haha!