How to format payload in POST request to add option to dropdown custom field

I’m trying to use the REST API to add a new option to a preexisting dropdown custom field in Trello, following the [API documentation here](https://developer.atlassian.com/cloud/trello/rest/api-group-customfields/#api-customfields-id-options-post). However, there’s no documentation for how the payload should be formatted. I’ve tried several configurations and keep getting either “Invalid custom field item value” or “Error parsing body” error messages. Any help is much appreciated!

Hello @AaronSmith

Firstly, the best way for others to understand what might be wrong is to provide actual code examples of the request you are making and the body of the request.

In the overwhelming majority of cases, you POST or PUT data in the same JSON format that it is provided via a GET request to the same or an adjacent endpoint.

So, to know the format for a custom field’s option, do a GET request to the Get option of Custom Field dropdown endpoint for one of the existing options in that custom field, which will yield a response something like this:

{
    "id": "60cd97c3199236728d9cf992",  <-- The ID of the custom field
    "idCustomField": "60cd9792d094da669588debb",  <-- The ID of the option
    "value": {
        "text": "Green option"  <-- The text in the option
    },
    "color": "green",  <-- The color of the option
    "pos": 16384  <-- The position of the option
}

Since you know you can’t set idCustomField or pos, as they are set automatically, all that’s left is being able to set value and color in the same format provided.

So, assuming you wanted to add a new red option, the format of the POST request would:
POST https://api.trello.com/1/customFields/60cd97c3199236728d9cf992/options

the body of the request would be:

{
    "value": {
        "text": "New red option"
    },
    "color": "red",
    "key" : "{{TrelloKey}}",
    "token" : "{{TrelloToken}}"
}
1 Like

Thanks so much for your response, David! I am new to all this so I appreciate the reminder to include code examples and will do that going forward.

So now after implementing what you said, my request looks like this in Terminal (I removed my API key and token for obvious security reasons):

curl --request POST --url 'https://api.trello.com/1/customFields/609d586c764bb3251dc2607b/options' --header 'Accept : application/json' --header 'Content-Type : application/json' --data '{ 
    "value" : {
        "text" : "New red option"
    },
    "color" : "red", 
    "key" : "[hidden for security]", 
    "token" : "[hidden for security]"
}'

I’m getting this in response:

curl: (52) Empty reply from server

In Trello, I don’t see a new option added to the dropdown field I’m posting to, so it’s not working. I know I’m posting to the right field id with the right key and token, because I was able to send a GET request using all the same info, and get an accurate response containing all the field options.

Can you see anything else I’m missing?

It looks like you’ve mal-formed the --data part of the cURL request. It needs to be a single line:

curl --request POST --url 'https://api.trello.com/1/customFields/609d586c764bb3251dc2607b/options' --header 'Accept : application/json' --header 'Content-Type : application/json' --data '{"value":{"text":"New red option"}, "color":"red", "key":"[hidden for security]", "token":"[hidden for security]"}'

Google ‘curl post body’ for many examples.

I suggest you start with an API test tool like Postman to test your requests first, before you commit them to code, then you can at least determine if it is the request that is faulty or your coding.

Good luck with your coding adventure.