Creating Trello Cards Automatically by Using Mule 4

18 May, 2021 | 3 minutes read

With remote and home working set to continue in 2021 during the Covid-19 pandemic, Trello as a project management and team collaboration tool has become one of the best and cheapest (Enterprise, Business Class, and Free, forever) solutions for the task management system.

It is a project management software that enables organizing a project into boards. Basically, it is the digital version of good old sticky notes. In addition, it can be easily customized and used instead of CRM software for businesses with simpler sales processes.

The best way to manage tasks with ease and accelerate everyday operations is to automate the process completely. The automation eases tracking errors which enables opening Trello board cards with to-do tasks without human interaction. This is very useful, as it provides detailed card information about created errors and enables a prompt reaction of the team.

This solution is based on automatically creating a Trello card in case of an error in a MuleSoft application.

MuleSoft provides the most widely used integration platform to connect any application, data service, or an API, across the cloud and on-premise continuum.

To use the MuleSoft Trello Connector, you should search for it in Exchange and then add the Trello Connector – Mule 4 dependency (Check Image 1).

Add Dependencies to Project
(Image 1: Add Dependencies to Project)

Base Uri, key and token parameters are needed for the configuration. (Check Figure 2). For more details about how to get the Trello key and token please check the following link:

https://developer.atlassian.com/cloud/trello/guides/rest-api/api-introduction/

Trello Connector Config
(Image 2 – Trello Connector Config)

To demonstrate the card creation in Trello, a simple Mule flow is created (Check Image 3), which will fail to process the Transform Message component due to the “Cannot coerce String (invalid date) to Date” error. The message will be sent to the Error-Handler where On Error Propagate is configured to catch all types of errors (Check Image 4).

MuleSoft flow
(Image 3 – MuleSoft flow)

In order to prevent card duplication in Trello, an additional logic should be applied, which makes a call to retrieve all cards from a specific board. This is accomplished using the Get Boards Cards By Id Board Mulesoft connector (Image 4).

(Image 4 – Error-Handler)

In the general part of the Get Boards Cards By Id Board connector, it is specified to return all the cards that are created in the last two days, with a maximum limit of 100 cards. In the field part, a list that consists of fields that should be received as part of the response is set.

According to the error.detailedDescription generated from the Mule application’s error handler and IdList field from the Trello response, we can check if a ticket with the same error description exists in the TODO, Doing or Done section.

Trello board
(Image 5 – Trello board)

The Choice router is using the below dataweave script (Check Figure 6), to prevent duplicate card creation by checking if the ticket with the same description is already created in TODO or Doing stage of the board. If the ticket exists in the board, the choice component will route the message to the upper path that will simply log “Card is already created”.

If the message is sent to the Default route, the MuleSoft Add Cards connector will create a new Trello card. The below JSON Object (Check Image 7) contains all available fields that can be sent as a Content parameter in the Add Cards connector.

%dw 2.0
output appilcation/java
---
using (idList = payload[?($.desc contains error.detailedDescription)].idList default [])
((idList contains p("trello.idList.TODO")) or (idList contains p("trello.idList.Doing")))

(Image 6 – DataWeave script)

%dw 2.0
output application/json
---
{
	"name"           : "APP: " ++ p('app.name') ++ " / ENV: " ++ p('env') ++ 		                   " / ERROR: " ++ error.errorType.asString,
	"desc"           : error.detailedDescription,
	"pos"            : if (p('env') == "prod") "top" else "bottom",
	"due"            : ( now() + |P2D| ) as Date {format: "yyyy-MM-dd"},
	"dueComplete"    : null,
	"idList"         : p("trello.idList.TODO"),
	"idMembers"      : p("trello.idMemberName"),
	"idLabels"       : null,
	"urlSource"      : null,
	"fileSource"     : null,
	"idCardSource"   : null,
	"keepFromSource" : null,
	"address"        : null,
	"locationName"   : null,
	"coordinates"    : null	
} filterObject $ != null

(Image 7 – Content JSON Object)

The main point of MuleSoft and Trello integration is to reduce the time needed to act upon a particular ticket being created when an application error occurs. The errors which require attention and need placement on a Trello board for further action, are highly configurable and adjustable based on a specific business need. This way, the overall client experience is improved by enabling the teams to focus on the card content, rather than card creation, which ultimately saves time and reduces cost.