Mini-Guide: Automating Trello with Robin

This mini-guide shows first steps at automating Trello with Robin. To keep it brief, it’s limited to creating a board.
The guide assumes you have done the following:

  1. Signed up for Trello and created your account
  2. Learned just enough Trello to navigate the web interface.

To use the Trello API, you’ll need a key, a token, and perhaps a secret (although you won’t need the secret for this guide).
The steps to get your key, token and secret can be found at this link:

Once you have your key and token, create a text file containing the key (I called mine ‘myKey.txt’) and save it somewhere you can easily reference it in your script. Do the same for your token (I called mine ‘myToken.txt’). This will keep your information out of the public eye, at least somewhat. We use File.ReadText to get the key and token into our variables.

You could also insert your key and token directly in your code, but (security considerations aside) that would limit (or destroy) portability.

POSTING TO TRELLO:
The easiest way to get information in and out of Trello is to compose URLs as if they were ‘cURL’ requests. Here’s an example given from the Trello API documentation:

(Example for creating a board)
curl --request POST --url 'https://api.trello.com/1/boards/?name={name}'

Here’s the code.

set myUrl to "https://api.trello.com/1/boards/?"

file.ReadText File: "C:\work\RobinTests\Trello\myKey.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> KeyContent

file.ReadText File: "C:\work\RobinTests\Trello\myToken.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> TokenContent
                
set myKey to KeyContent
set myToken to TokenContent
set boardName to "My Robin Test Board"
set fullUrl to myUrL + "key=" + myKey + "&token=" + myToken + "&name=" + boardName

web.InvokeWebService \
                        Url: fullUrl\
                        Method:Web.Method.Post \
                        Accept: 'application/xml' \
                        ContentType:'application/xml' \
                        CustomHeaders:'' \
                        RequestBody: '' \
                        ConnectionTimeout:30 \
                        FollowRedirection:True \
                        ClearCookies:False \
                        FailOnErrorStatus:False \
                        EncodeRequestBody:False \
                        UserAgent:'' \
                        Encoding:'' \
                        ResponseHeaders=> ResponseHeaders \
                        Response=> WebServiceResponse \
                        StatusCode=> StatusCode 
                                                                     
Console.Write Message: WebServiceResponse
Console.Write Message: ResponseHeaders
Console.Write Message: StatusCode

Variables.ConvertJsonToCustomObject \
              Json: WebServiceResponse \
              CustomObject=> JsonAsCustomObject
              
Console.Write Message: JsonAsCustomObject
Console.Write Message: JsonAsCustomObject.id
Console.Write Message: JsonAsCustomObject.name
Console.Write Message: JsonAsCustomObject.url
Console.Write Message: JsonAsCustomObject.labelNames

And a screenshot:

As you can see, we’ve dispensed with everything in our call to

Web.InvokeWebService

except our composed URL to accomplish what we want. This is quick, dirty, and just works.

GETTING INFORMATION BACK FROM TRELLO
The Trello response (‘WebServiceResponse’) contains lots of data (run the script and see). To make further use of it, you’ll likely want to use
Variables.ConvertJsonToCustomObject’.

if you do this, you can access all the Trello data returned by using dot notation on your Custom Object (see examples below from the code).

Console.Write Message: JsonAsCustomObject
Console.Write Message: JsonAsCustomObject.id
Console.Write Message: JsonAsCustomObject.name
Console.Write Message: JsonAsCustomObject.url
Console.Write Message: JsonAsCustomObject.labelNames

Trello’s API is vast. Using the information you’ve acquired here, you can go farther and automate the whole thing.

After you’ve run this script, you’ll probably want to delete your test board!

Regards,
burque505

2 Likes

Here’s an updated version of the script above that creates a new List in the board just created:

set myBoardsUrl to "https://api.trello.com/1/boards/?"
set myListsURL to "https://api.trello.com/1/lists/?"

file.ReadText File: "C:\work\RobinTests\Trello\myKey.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> KeyContent

file.ReadText File: "C:\work\RobinTests\Trello\myToken.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> TokenContent
                
set myKey to KeyContent
set myToken to TokenContent
set boardName to "My Robin Test Board"
set fullUrl to myBoardsUrL + "key=" + myKey + "&token=" + myToken + "&name=" + boardName

web.InvokeWebService \
                        Url: fullUrl\
                        Method:Web.Method.Post \
                        Accept: 'application/xml' \
                        ContentType:'application/xml' \
                        CustomHeaders:'' \
                        RequestBody: '' \
                        ConnectionTimeout:30 \
                        FollowRedirection:True \
                        ClearCookies:False \
                        FailOnErrorStatus:False \
                        EncodeRequestBody:False \
                        UserAgent:'' \
                        Encoding:'' \
                        ResponseHeaders=> ResponseHeaders \
                        Response=> WebServiceResponse \
                        StatusCode=> StatusCode 
                                                                     
Console.Write Message: WebServiceResponse
Console.Write Message: ResponseHeaders
Console.Write Message: StatusCode

Variables.ConvertJsonToCustomObject \
              Json: WebServiceResponse \
              CustomObject=> JsonAsCustomObject
              
Console.Write Message: JsonAsCustomObject
Console.Write Message: JsonAsCustomObject.id
Console.Write Message: JsonAsCustomObject.name
Console.Write Message: JsonAsCustomObject.url
Console.Write Message: JsonAsCustomObject.labelNames

set boardId to JsonAsCustomObject.id
set cardName to "New Robin List"
# Add a list
# curl --request POST   --url 'https://api.trello.com/1/lists?name={name}&idBoard=5abbe4b7ddc1b351ef961414'
set fullCardUrl to myListsUrL + "key=" + myKey + "&token=" + myToken + "&name=" + cardName + "&idBoard=" + boardId

# Console.Write Message: "Card URL looks like " + fullCardUrl

web.InvokeWebService \
                        Url: fullCardUrl\
                        Method:Web.Method.Post \
                        Accept: 'application/xml' \
                        ContentType:'application/xml' \
                        CustomHeaders:'' \
                        RequestBody: '' \
                        ConnectionTimeout:30 \
                        FollowRedirection:True \
                        ClearCookies:False \
                        FailOnErrorStatus:False \
                        EncodeRequestBody:False \
                        UserAgent:'' \
                        Encoding:'' \
                        ResponseHeaders=> ResponseHeaders \
                        Response=> CreateListResponse \
                        StatusCode=> StatusCode 
                        
Console.Write Message: CreateListResponse

Variables.ConvertJsonToCustomObject \
              Json: CreateListResponse \
              CustomObject=> JsonAsCustomObject
              
set myListId to JsonAsCustomObject.id

Console.Write Message: myListId

Regards,
burque505

GETTING INFORMATION BACK FROM TRELLO WITH ‘GET’ REQUEST

This code uses an example from the Trello API to get some board information.
Please note the workaround (hopefully useful elsewhere) using
Text.Parse
for dealing with Custom Object “keys” that have no value or empty values.

The term key may well be incorrect in this context, but if we consider a Robin Custom Object as consisting of key-value pairs there should be no real confusion .

set myListsGetURL to "https://api.trello.com/1/members/me/boards?"

file.ReadText File: "C:\work\RobinTests\Trello\myKey.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> KeyContent

file.ReadText File: "C:\work\RobinTests\Trello\myToken.txt" \
                Encoding:File.TextFileEncoding.UTF8 \
                Content=> TokenContent
                
set myKey to KeyContent
set myToken to TokenContent
set getListsURL to myListsGetUrL + "key=" + myKey + "&token=" + myToken
set emptyString to ''

web.InvokeWebService \
                        Url: getListsUrl\
                        Method:Web.Method.Get \
                        Accept: 'application/xml' \
                        ContentType:'application/xml' \
                        CustomHeaders:'' \
                        RequestBody: '' \
                        ConnectionTimeout:30 \
                        FollowRedirection:True \
                        ClearCookies:False \
                        FailOnErrorStatus:False \
                        EncodeRequestBody:False \
                        UserAgent:'' \
                        Encoding:'' \
                        ResponseHeaders=> ResponseHeaders \
                        Response=> WebServiceResponse \
                        StatusCode=> StatusCode 
                                                                     
Console.Write Message: WebServiceResponse
Console.Write Message: ResponseHeaders
Console.Write Message: StatusCode

Variables.ConvertJsonToCustomObject \
              Json: WebServiceResponse \
              CustomObject=> BoardListObject
        
Console.Write Message: BoardListObject

# Console.Write Message: BoardListObject.Count
# Use this property to set the indexer for the following loop.

set indexer to BoardListObject.Count

loop i from 1 to indexer step 1
    # Console.Write message: BoardListObject[i-1]
    # Use this workaround for keys in the custom object that have no value
    Text.Parse Text: BoardListObject[i-1] TextToFind: "'dateLastActivity': ," StartingPosition: 0 IgnoreCase:False OccurrencePositions=> FoundIt
    #Console.Write Message: FoundIt
    If (FoundIt < 0) then
    Console.Write Message: "Board '" + BoardListObject[i-1].name + "' was last active on " + BoardListObject[i-1].dateLastActivity + "."
    else 
    Console.Write Message: "Board '" + BoardListObject[i-1].name + "' has no activity yet."
    end
end

Partial script results from my system and Trello state:

Board 'Learn Trello' was last active on 5/26/2020 6:03:43 PM.
Board 'My Robin Test Board' has no activity yet.
Board 'Time tracking' was last active on 6/9/2020 11:41:40 PM.
Execution completed successfully.

Regards,
burque505

1 Like