Why am I getting a bad HTTP 400 Request Error?


Achieve

I simply want to make a webhook bot to go to my discord server when I trigger.

Issues

I get a HTTP 400 Error. I’m also having an issue of grabbing the games Icon/Thumbnail.

Solutions

I’ve tried rewriting the entire scripts, making new bots and getting new HTTP Links and nothing works.


Script

function DiscordShouts(plr,Send,One,Two,Three,Four,Five,Six,Seven)
	local function ColorTransfer(c)
		return math.floor(c.R*255)*256^2+math.floor(c.G*255)*256+math.floor(c.B*255)
	end --GotFromTMB
	local HS = game:GetService("HttpService")
	local Place = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId)
	local PlaceLink = "https://www.roblox.com/games/"
	--[[ShowName, StartTime, Color]]
	if Send == "Results" then
		--[[ShowName,Result,Color,Matchtype]]
		local MessageData = {
			["embed"] = {
				["color"] = ColorTransfer(Three),
				["thumbnail"] = {
					["url"] = "https://www.roblox.com/asset-thumbnail/image?assetId="..Place.."&width=768&height=432&format=png"
				},
				["fields"] = 
				{
					["name"] = "Result",
					["value"] = Two
				},
				{
					["name"] = "Match Type",
					["value"] = Four,
					["inline"] = false
				},
				{
					["name"] = "Place Located",
					["value"] = "Where At",
					["inline"] = true
				},
				{
					["name"] = "Who Sent",
					["value"] = plr.Name,
					["inline"] = true
				}
			}
		}
		MessageData = HS:JSONEncode(MessageData)
		HS:PostAsync(MatchResultsWebhook,MessageData) --The MatchResultsWebhook goes to a StringValue that is set to a HTTP Value.
	end
end

Thank you to anyone who’s willing to help.

What is MatchResultsWebhook defined as? It’s your webhook URL, right?

Yes, the MatchResultsWebhook goes to a StringValue that is set to a HTTP Value.

I don’t fully understand your code from the snippet you gave, so I’m going to give you a full example of a basic webhook.

local HttpService = game:GetService("HttpService")
local URL = "" -- This is the reference to the webhook URL (must be string)

local Data = { -- This is our Lua table containing some information about our webhook so Discord knows how to display it.
	["content"] = "",
	["embeds"] = {{
		["title"] = "__**Ultimate Title**__", -- title of the embed
		["description"] = "blah blah", -- description
		["type"] = "rich",
		["color"] = tonumber(0xffffff), -- This is the color of the side slot of the embed message. It is in HEX format. You will need to look up an online converter to get the desired color you'd like
		["fields"] = {
			{
				["name"] = "__Title__",
				["value"] = "hi",
				["inline"] = true
			},
			{
				["name"] = "__Title__",
				["value"] = "hi",
				["inline"] = true
			}
		}
	}}
}

local EncodedData = HttpService:JSONEncode(Data) -- In order for Discord to read your data properly, you need to convert your data to JSON format. Luckily, this is easy with HttpService:JSONEncode()
HttpService:PostAsync(URL, EncodedData) -- This final statement is our HTTP call to Discord. We're sending our data over for Discord to display the message.

Result:


This is an example of the embed structure that you’d send.
You can read more about embed structure in detail here.
This is a nice tool for helping you build your embed structure.

If you’re still getting the HTTP 400 error, it’s likely you have an incorrect URL (or some of your data you’re sending isn’t correct). Learn how to properly create a webhook here.

This is the endpoint for grabbing the game’s thumbnail:
https://www.roblox.com/asset-thumbnail/image?assetId=PLACE_ID_HERE&width=420&height=420&format=png
replace PLACE_ID_HERE with your place ID.

As for getting the game’s icon, you can do the following:

local HttpService = game:GetService("HttpService")
local PLACEID = 4061596946

local UniverseID = HttpService:JSONDecode(HttpService:GetAsync("https://api.rprxy.xyz/universes/get-universe-containing-place?placeid="..PLACEID)).UniverseId
local IconUrl = HttpService:JSONDecode(HttpService:GetAsync("https://thumbnails.rprxy.xyz/v1/games/icons?universeIds="..UniverseID.."&size=256x256&format=Png&isCircular=false")).data[1].imageUrl

^ that took an EXTREMELY long time to figure out, you’re welcome

Discord official webhook docs: Discord Developer Portal

4 Likes