0

I'm using the trello API to get info from a card but I don't know how to get the values set on a custom field.

Here you can see a card with a couple of custom fields and some calues set in those. enter image description here

When I do a GET request to https://api.trello.com/1/cards/{cardId}?key={trelloKey}&token={trelloToken}&card_customFieldItems=true I can get the card info like this

{
  "id": "6022f966865fcb70b03f8cb3",
  "badges": {
    "attachmentsByType": {
      "trello": {
        "board": 0,
        "card": 0
      }
    },
    "location": false,
    "votes": 0,
    "viewingMemberVoted": false,
    "subscribed": false,
    "fogbugz": "",
    "checkItems": 30,
    "checkItemsChecked": 5,
    "checkItemsEarliestDue": null,
    "comments": 48,
    "attachments": 0,
    "description": true,
    "due": "2021-07-22T22:54:23.000Z",
    "dueComplete": false,
    "start": "2021-08-11T00:00:00.000Z"
  },
  "checkItemStates": [
    {
      "idCheckItem": "61a65b5df97d530c5fa6dbac",
      "state": "complete"
    },
    {
      "idCheckItem": "612d013f446e1806f55af402",
      "state": "complete"
    },
    {
      "idCheckItem": "616522ea10fc1b8e352d04b0",
      "state": "complete"
    },
    {
      "idCheckItem": "616525ecd463b0671871e0ae",
      "state": "complete"
    },
    {
      "idCheckItem": "60f9f65443f17d509472439a",
      "state": "complete"
    }
  ],
  "closed": false,
  "dueComplete": false,
  "dateLastActivity": "2023-03-22T14:39:14.901Z",
  "desc": "some description",
  "descData": null,
  "due": "2021-07-22T22:54:23.000Z",
  "dueReminder": -1,
  "email": null,
  "idBoard": "5b7bf48f8439ad2c1d5359e8",
  "idChecklists": [
    "60f9f65097429c7669ec25b2",
    "60f9f650ac549119b952e57e",
    "60f9f651310ae602d4b2b25e",
    "60f9f651b5c1d60c0d076962",
    "60f9f6543cbf4519bc3a1d2d",
    "60f9f65423b32263c93ab2c9",
    "60f9f65443f17d5094724396",
    "623486b041358424196a7000",
    "631898f2ee40800125606c38"
  ],
  "idList": "601d140c0e86f707796d05c1",
  "idMembers": [
    "5cbe5c943c8d27750b5e27f2"
  ],
  "idMembersVoted": [],
  "idShort": 605,
  "idAttachmentCover": null,
  "labels": [],
  "idLabels": [],
  "manualCoverAttachment": false,
  "name": "Test - Jomar - 2/9/2021 21:04:56: $45",
  "pos": 817539754.6666666,
  "shortLink": "6y9J6umX",
  "shortUrl": "https://trello.com/c/6y9J6umX",
  "start": "2021-08-11T00:00:00.000Z",
  "subscribed": false,
  "url": "https://trello.com/c/6y9J6umX/605-test-jomar-2-9-2021-210456-45",
  "cover": {
    "idAttachment": null,
    "color": null,
    "idUploadedBackground": null,
    "size": "normal",
    "brightness": "light",
    "idPlugin": null
  },
  "isTemplate": false,
  "cardRole": null
}

But there's no custom fields. Then I can do a GET request to https://api.trello.com/1/cards/{cardId}/customFieldItems?key={trelloKey}&token={trelloToken}&card_customFieldItems=true and that way i can get the custom fields of that card

[
  {
    "id": "6418dfc87cd38440817413bb",
    "idValue": "602fc6c6a6ed4e4c1ec070f6",
    "idCustomField": "600841c33b833e52356627d4",
    "idModel": "6022f966865fcb70b03f8cb3",
    "modelType": "card"
  },
  {
    "id": "6089ffb9de6d2e0a2b92c3c5",
    "idValue": "60083fcaea399523d6a91ed0",
    "idCustomField": "60083fcaea399523d6a91ecd",
    "idModel": "6022f966865fcb70b03f8cb3",
    "modelType": "card"
  },
  {
    "id": "6418dfc2f3eeda2c1ca3486e",
    "idValue": "5f7c96ff499bee6e6c91c8a8",
    "idCustomField": "5f7c96ff499bee6e6c91c8a7",
    "idModel": "6022f966865fcb70b03f8cb3",
    "modelType": "card"
  },
  {
    "id": "63dcd004cf343905f3e4dd01",
    "value": {
      "text": "Jomar Garcia"
    },
    "idCustomField": "5f7c9682ceaf796852a56cc3",
    "idModel": "6022f966865fcb70b03f8cb3",
    "modelType": "card"
  }
]

As you see, the only field that comes with the exact value of the field is the last one and if you check the image that corresponds to the field expertbut hte rest of the results return an idValue and I can't find any documentaiton (in the trello API) related to how to get those values with that idValue. I found another questions related to this topic, the most important is this one How to get/set Trello custom fields using the API? but I couldn't find a way to get the real result of those custom fields.

vimuth
  • 5,064
  • 33
  • 79
  • 116

1 Answers1

0

Except for custom fields of the type text, the REST API endpoints never return the value of the option directly when you query its value per card, only its ID.

Once you have the ID of the custom field and the ID of the option that has been selected for that card, you need to do a follow-up lookup of the 'real' value associated with that ID. You need to use either the Get Custom Field Items for a card or Get a Custom Field endpoints to 'translate' all the option IDs back to values available for a specific custom field.

Refer to this thread in the Atlassian Community forum where I describe the whole thing in greater detail.

Yes, it's double handling, but it's not a bad thing, since it allows a custom field to have multiple identical option values, but you can differentiate them by their unique IDs.

David Bakkers
  • 453
  • 3
  • 13