1

Is there a way to update the CheckItemStates of a Trello card? (With Trello.NET)

trello.Checklists.AddCheckItem takes only a checklist ID and a name for the item. And it returns void.

Looking at a card with an existing checklist (all the items still unchecked) the CheckItemStates has 0 items.

Ron Harlev
  • 16,227
  • 24
  • 89
  • 132

1 Answers1

3

Checklists in Trello are a bit weird. A checklist belongs to a board. The same checklist can be on several cards. But each card has separate checklist item states (checked/unchecked). I don't think it's possible to add the same checklist to more than one card on trello.com, but that's how it's modeled behind the scenes.

As of release 0.5.5-beta Trello.NET supports this. Use Trello.Cards.ChangeCheckItemState. More info here.

Edit:

This example shows how to loop through a card´s check lists and check items.

foreach (var checkList in trello.Cards.WithId("a card id").Checklists)
{
    Console.WriteLine(checkList.Name);

    foreach (var checkItem in checkList.CheckItems)             
        Console.WriteLine("\t{0}: {1}", checkItem.Name, checkItem.Checked);
}
dillenmeister
  • 1,627
  • 1
  • 10
  • 18
  • Was this feature removed or am I not searching in the right place? I only see a Name and Id for the CheckItems, no Checked state... – Anders Forsgren Jun 10 '13 at 20:16
  • Thanks, that is exactly what I'm doing but I don't see the `Checked` property on the items (which are of type `TrelloNet.CheckItem`), just `Name` and `Id`! Am I looking at the wrong class? I'm using 0.5.9 and it looks the same here: https://github.com/dillenmeister/Trello.NET/blob/master/TrelloNet/Checklists/CheckItem.cs – Anders Forsgren Aug 16 '13 at 21:45
  • There are actually two classes. `Card.CheckItem` (private class on `Card`) inherits from "regular" `CheckItem` and adds the `Checked` property. This is because the `Checked` property is not an actual property of `CheckItem` in the Trello API and there is some special logic when deserializing a `Card` to set the `Checked` property on all `CheckItems`. Here is the code for that: https://github.com/dillenmeister/Trello.NET/blob/master/TrelloNet/Cards/Card.cs#L68. The data model is a bit weird as I tried to explain in the answer. Did you try my example code? – dillenmeister Aug 20 '13 at 07:55
  • Aha, I stumbled on the difference between `trello.CheckLists.ForCard(card)` and `card.CheckLists` of course. They have sure invented a smelly datamodel for checklists it seems. Thanks. – Anders Forsgren Aug 21 '13 at 18:46