How to update a trello custom field using HTTP POST?

My question is pretty much the above. I’m able to do GET requests and have all the appropriate parameters needed for a POST url. The issue is, I’m not really sure how to work it… my token and id are valid.

local response = HttpService:PostAsync(HttpService:UrlEncode("https://api.trello.com/1/cards/"..PlrInfo.id.."/customField/"..efields.idCustomField.."/item?key=" .. Key .. "&token=" .. Token), "hi")

When I try sending this, I get a 400 error (bad request)

Please help! :slight_smile:

Hi
According to the Trello documentation, to update a custom field you need to use this endpoint, which requires a PUT request not POST, for that you’d need to use RequestAsync (which is recommended instead of Get/PostAsync anyways). Here’s the code I used to achieve it:

local http = game:GetService("HttpService")

-- Fill these variables with your data --
local card_id = ''
local field_id = ''
local key = ''
local token = ''

local url = ('https://api.trello.com/1/cards/%s/customField/%s/item?key=%s&token=%s'):format(card_id, field_id, key, token)
local updateData = {
	value = {
		text = 'hi'
	}
}

local options = {
	Url = url,
	Method = 'PUT',
	Headers = {
		["Content-Type"] = "application/json"
	},
	Body = http:JSONEncode(updateData)
}

local ok, response = pcall(function()
	return http:RequestAsync(options)
end)

if ok and response.Success then
	print('Succesfully updated!')
else
	warn("Could not update:", response)
end

Hiya, I used your code and I changed the value to number because my custom field is a number. I have this error, any idea what’s up? (I’ve taken out they key and token for this post obviously but it’s there)
image

function AutoLoopData.PatrolLog(Plr, Time)
	local PlrInfo
	for i, v in pairs(Staff) do
		if v.name == Plr.Name then
			PlrInfo = v
		end
	end
	local e = HttpService:JSONDecode(HttpService:GetAsync("https://api.trello.com/1/cards/"..PlrInfo.id.."/customFieldItems?key=" .. Key .. "&token=" .. Token))
	local efields = e[1]
	local http = game:GetService("HttpService")

	-- Fill these variables with your data --
	local card_id = PlrInfo.id
	local field_id = efields.idCustomField

	local url = ('https://api.trello.com/1/cards/%s/customField/%s/item?key=%s&token=%s'):format(card_id, field_id, Key, Token)
	local updateData = {
		value = {
			number = 0
		}
	}

	local options = {
		Url = url,
		Method = 'PUT',
		Headers = {
			["Content-Type"] = "application/json"
		},
		Body = http:JSONEncode(updateData)
	}

	local ok, response = pcall(function()
		return http:RequestAsync(options)
	end)

	if ok and response.Success then
		print('Succesfully updated!')
	else
		warn("Could not update:", response)
	end
end

(Staff is just a table with cards from a certain list)

pretty sure you the value of the number key still has to be a string. simply replace

value = {
	number = 0
}

with

value = {
	number = "0"
}

Hiya, that worked to get rid of 1 issue however it says ‘unauthorized card permission requested’. I’m not exactly sure what’s up. I think it’s got something to do with my token
image
DISREGARD THIS, I got a new token and it fixed it.