"HTTP 400 (Bad Request)" even though JSON data is correct

Hello, I ran into a problem when wanting to send a webhook whenever a player has joined. The JSON data I wanted to post to my webhook looks like this:

{
   "embeds":[
      {
         "color":65280,
         "fields":{
            "name":"Player properties",
            "value":"Premium membership: false\nCountry: :flag_de: Germany"
         },
         "title":"A player has joined",
         "description":"Doct0r_Br1ght (562332673) has joined the game!"
      }
   ]
}

It somehow works for the leave embed, now I wonder what I did wrong while sending the first embed.
This is the JSON for the second embed:

{
   "embeds":[
      {
         "color":16711680,
         "title":"A player has left!",
         "description":"Doct0r_Br1ght (562332673) has left the game!\n>>> Minutes spent: 0\nPremium: false"
      }
   ]
}

This is the lua code for both:

		-- (webhookLink, plr and HttpService are defined)
		local joinEmbed = {
			["title"] = "A player has joined",
			["description"] =  plr.Name.." ("..tostring(plr.UserId)..") has joined the game!",
			["color"] = tonumber(0x00ff00),
			["fields"] = {
				["name"] = "Player properties",
				["value"] = tostring("Premium membership: "..tostring(plr.MembershipType == Enum.MembershipType.Premium).."\nCountry: :flag_"..plrLocation:lower()..": "..countryTable[plrLocation])
			}
		}

		HttpService:PostAsync(webhookLink, HttpService:JSONEncode({ ["embeds"] = { joinEmbed } }))

	local leaveEmbed = {
		["title"] = "A player has left!",
		["description"] =  plr.Name.." ("..tostring(plr.UserId)..") has left the game!\n>>> Minutes spent: "..plr.leaderstats.Minutes.Value - savedTime.."\nPremium: "..tostring(plr.MembershipType == Enum.MembershipType.Premium),
		["color"] = 0xff0000
	}

	HttpService:PostAsync(webhookLink, HttpService:JSONEncode({ ["embeds"] = { leaveEmbed } }))

Thrown error:

1 Like

Probably due to the fact that studio might not be 100% compatible with that type of script. It looks like you want to make it say user has left the game or user has joined the game. Since your in a studio testing mode studio might not like the request. Try testing it on roblox itself. Other than that I dont know lol.

fields must by array. In JSON:

"fields": [
        {
          "name": "Player properties",
          "value": "Premium membership: false\nCountry: :flag_de: Germany"
        }
      ]

In lua:

{
...
	["fields"] = {
		{["name"] = "Player properties", ["value"] = "Premium membership: false \nCountry: :flag_de: Germany"}
	}
...
}
1 Like

Ooooooooooh, thank you!!!⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

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