Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,460,039
Community Members
 
Community Events
176
Community Groups

Is there any way on api to get values of dropdown type custom fields?

Hello, we have a power-up app on trello; however, we cannot get values of custom fields that are with type of "dropdown". Is there any way to retrieve?

API URL: GET https://api.trello.com/1/board/607eb929ee33c047e810692f/cards?customFieldItems=true&fields=name&key={key}&token={token}

Response:

Screen Shot 2021-08-06 at 00.02.31.png

3 answers

1 accepted

1 vote
Answer accepted

Hello @Turan Gurler 

In the response from the REST API, for the dropdown custom fields, it will only tell you the ID of the option that's been selected for that field:

{
  "id": "60cd9a5dc324113a527ad8ff",
  "idValue": "60cd97c3199236728d9cf992",    <- The id of the option selected
  "idCustomField": "60cd9792d094da669588de05",   <- The id of the field
  "idModel": "607e32a184fead458a199e07",
  "modelType": "card"
}

To translate that ID value back into what that option contains (IE the text and the color) you have to query the Get a Custom Field endpoint using the ID of that dropdown custom field:

GET https://api.trello.com/1/customFields/60cd9792d094da669588de05?key={key}&token={token}

...and you will get back something like the following:

{
  "id": "60cd9792d094da669588de05",  <- The id of the field
  "idModel": "602786e91c69d30e45a9ccd8",
  "modelType": "board",
 "fieldGroup": "bba6783271ae2131251b190534817d1ccadd217b2267540b434cbdaf417866c9",
  "display": {
    "cardFront": true
  },
  "name": "Dropdown choices",
  "pos": 49152,
  "options": [
    {
      "id": "60cd97c3199236728d9cf992",  <- The id of the option
      "idCustomField": "60cd9792d094da669588de05", <- The id of the field, again
      "value": {
          "text": "Green option<- The text for that option
      },
     "color": "green",   <- The color for that option
     "pos": 16384    <- The position of that option within the field (the order)
    },
  {
      "id": "60cd97c791d7b954b63dbaeb",
      "idCustomField": "60cd9792d094da669588de05",
     "value": {
       "text": "Red option"
     },
    "color": "red",
    "pos": 32768
    }
   ],
  "type": "list",
  "limits": {
  "customFieldOptions": {
    "perField": {
      "status": "ok",
      "disableAt": 50,
      "warnAt": 45
    }
  }
},
"isSuggestedField": false
}

From these two pieces of data, it's now known that the dropdown custom field called 'Dropdown choices' on a particular card has been set to the value 'Green option' and that option has the color 'green'.

The reason for this two-step approach is that the options available for the dropdown custom fields are stored at the board level, not the card level, so you have to query at the next level up, so to speak, to find what those options are, then correlate them to which one has been chosen for a particular card.

Hi David,

That will be a great solution! Thanks for the answer.

Hi David,

First off thank you so much for your answer. I'm facing the same Puzzle.

I went through your example and learned a lot.   I was able to complete it and get a list of all Options for my Custom field.

But how can I tell which option was selected?  The JSON doesn't reveal which option was selected by the user (that I can find).

Example:

I have custom field called: "First name", setup as a dropdown, and contains 4 options:

First Name

  James

  John Paul

  Robert

   John                 <<<<<==== Selected

If I select Option #4 "John" how do I perform a GET that tells me that this option was  selected?

 

User UI:

image.png

My Get call using the ID for my Custom Field "First Name":

image.png

 

JSON: Info on each option:

image.png

image.png

Apologies if I missed something in your example, I'm still Green with REST calls.

cheers,

Damon

Hello @ManniStudio 

The answer is in the OP's original question. You need to query the Get Custom Field Items for a Card endpoint, which will tell you the IDs of any options that have been set per custom field per card.

Note. If this endpoint returns an empty set, it means no options have been set for any custom fields on that card.

For example, I have a board with custom drop-down field called 'Dropdown choices' and it has four choices (I can discover the field and its options from the Get Custom Fields for a Board endpoint).

On one particular card, that custom field has been set to the choice 'Purple option':

Card.png

I lookup the custom field items for that card:

GET https://api.trello.com/1/cards/631ed7381a8cfb00e091c317/customFieldItems?key=blah&token=blah

And the response tells me:

[
 {
  "id": "631ed7381a8cfb00e091c317",
  "idValue": "60ce91cf104a13124295ec0e", <-- id of the option selected
  "idCustomField": "60cd9792d094da669588de05", <-- id of the custom field
  "idModel": "62c545eaaa69773929397646",
  "modelType": "card"
 }
]


So, I then just compare the ID of the option selected for that custom field for that card with the knowledge I already know about that custom field via either the Get a Custom Field endpoint or the Get Custom Fields for a Board endpoint to reverse 'translate' the option ID back to the text content for that option.

I never used API, but I do access the JSON file through Power BI. I believe the problem here is that you're accessing the "Cards" section of the database. This will bring the value set for the cards.

Instead, you should be going for the "customFields" portion of the database. Through that, you will be able to get all the data related to Custom Fields per se, like which fields you havem their ids, types, and 'Options', which is what you are looking for.

Maybe this will help?

untitled.png

Well, thanks for the reply but i'm looking for the API solution. 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events