csharp-trello-manatee

How to Connect with Trello from C# with Trello Manatee

  • 3 min

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

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

Trello Manatee is the reference C# library for precisely that, connecting in a simple and convenient way.

For example, I have used it frequently in some solutions where users employed Trello as a management system, and from there you would read the data from C# to perform your calculations, save them to a database, etc. (it saves you from building a UI and changing their workflow).

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

Finally, keep in mind that all the actions we are performing are done 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 for 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 so often), with your account logged in, go to this URL https://trello.com/app-key

Copy your personal key, which will be your AppKey, and then go to

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

Where you must replace [AppName] with your application’s name, 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 now 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 it, you will have to regenerate it.

Example in C#

Let’s see a simple example of how to use Trello Manatee to get a list of all cards on 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);
    }
}
Copied!

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

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

One of the peculiarities of Trello Manatee (and a positive point) is that it tries to minimize API calls to avoid penalizing performance. That’s why actions are not performed until “it’s 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 a bit confusing, that’s why I’m warning you).