Language: EN

csharp-trello-manatee

How to Connect with Trello from C# with Trello Manatee

Trello Manatee is a C# library that provides an interface to connect to the Trello API, and to access its resources for reading or writing.

If you work with Trello regularly, you may have needed to connect to its API to interact with your boards, lists, and cards, or to automate processes.

Trello Manatee is the reference C# library for connecting in a simple and comfortable way.

For example, I have frequently used it in a solution where users used Trello as a management system, and from there you read the data from C# to do your calculations, save them in a database, etc. (you avoid making a UI, and changing their way of working).

It is not a complex library to use. The only difficulty is to familiarize yourself with the object model that Trello uses. For this, you should rely on the library’s documentation.

Finally, keep in mind that all the actions we are doing are carried out through web requests. Although the library intelligently uses asynchronous and caching mechanisms, in general, access is “relatively slow”.

How to use Trello Manatee

We can easily add the library to a .NET project through the corresponding Nuget package.

Install-Package Manatee.Trello

Next, we will need the API key and access token to the Trello API. You can obtain them from the Trello website, in the developers section.

Or, if you want the quick way (because the developers section is a mess and changes every two by three), with your logged-in account, go to this URL https://trello.com/app-key

You copy your personal key, which will be your AppKey, and then you go to

https://trello.com/1/authorize?expiration=never&name=[AppName]&key=[AppKey]

Where you must replace [AppName] with the name of your application, and [AppKey] with the key you obtained in the previous step. When you accept the permissions, it will return a UserToken for authentication that you must copy and save.

Once you have the authentication data, AppKey and userToken, we can use the library to connect to the Trello API and perform operations on your boards, lists, and cards.

Logically, do not share this data with anyone, and keep it in a safe place. If you lose them, you will have to regenerate them.

Example in C#

Let’s see a simple example of how to use Trello Manatee to get a list of all the cards in a board

using Manatee.Trello;
using Manatee.Trello.Rest;

public void GetCards()
{
    TrelloAuthorization.Default.AppKey = "your-app-key";
    TrelloAuthorization.Default.UserToken = "your-user-token";

    var board = new Board("board-id");
    board.Refresh();

    var cards = board.Cards;

    foreach (var card in cards)
    {
        Console.WriteLine(card.Name);
    }
}

In this example, the API key and access token to the Trello API are set using the TrelloAuthorization class. Next, we create an instance of the Board object. You can see the board-id of your board in the URL, when accessed from the browser.

Then we use the Refresh() method to get the information of the board, we get all the cards of the board using the Cards property, and we show the name of each card in the console.

One of the peculiarities of Trello Manatee (and a positive point) is that it tries to minimize the calls to the API, to not penalize performance. That’s why the actions are not carried out until “it is really necessary”

That’s why in the example we had to call the ‘Refresh()’ method. Creating the board does not load its data until we specify it. You will find that working philosophy throughout the library (and sometimes it can be confusing, that’s why I’m warning you).

Trello Manatee is Open Source, and all the code and documentation is available in the project’s repository at https://github.com/micjahn/ZXing.Net