Cmdlets for Trello

Build 21.0.7930

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our Trello Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module TrelloCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module TrelloCmdlets;

You can then use the Connect-Trello cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-Trello -APIKey "myApiKey" -Token="myGeneratedToken"

Trello uses token-based authentication to grant third-party applications access to their API. When a user has granted an application access to their data, the application is given a token that can be used to make requests to Trello's API. Trello's API can be accessed in 2 different ways. The first is using Trello's own Authorization Route, and the second is using OAuth1.0.

Authenticate using the Trello Authorization Route

At the moment of registration, Trello assigns an API key and Token to the account.

Note: Set AuthScheme to Token to activate this authentication method.

At the moment of registration, Trello assigns an API key and Token to the account. We can retrieve this API key after logging in to Trello and visiting https://trello.com/app-key. After obtaining your API key, you can use it to obtain a Token by visiting https://trello.com/1/authorize?expiration=never&name=MyPersonalToken&scope=read&response_type=token&key={Key} and replacing {key} with the obtained API key. After visiting the page, you can authorize the application to use your account by clicking the allow button. You'll be redirected to a page with your token. To make requests to Trello's API you will need both API key and Token.

Note: You can change the expiration time of the token by changing expiration= with one of the following values (1hour, 1day, 30days, never).

Set:

  • APIKey: The key found at https://trello.com/app-key
  • Token: The token obtained

Authenticate using OAuth

Note: Set AuthScheme to OAuth to activate this authentication method.

Similar to using Authorization, OAuth creates an Application Id and Secret when you create your account. See Using OAuth Authentication for information on how to to connect.

Retrieving Data

The Select-Trello cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-Trello -Connection $conn -Table "Cards" -Columns @("Name, ListId") -Where "CardId='614060b2c37da423f30dc7d6'"
The Invoke-Trello cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-Trello -Connection $conn -Table Cards -Where "CardId = '614060b2c37da423f30dc7d6'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myCardsData.csv -NoTypeInformation

You will notice that we piped the results from Select-Trello into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-Trello -APIKey "myApiKey" -Token="myGeneratedToken"
PS C:\> $row = Select-Trello -Connection $conn -Table "Cards" -Columns (Name, ListId) -Where "CardId = '614060b2c37da423f30dc7d6'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "Cards",
  "Columns":  [

  ],
  "Name":  "MyName",
  "ListId":  "MyListId"
} 

Deleting Data

The following line deletes any records that match the criteria:

Select-Trello -Connection $conn -Table Cards -Where "CardId = '614060b2c37da423f30dc7d6'" | Remove-Trello

Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Trello, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyCardsUpdates.csv | %{
  $record = Select-Trello -Connection $conn -Table Cards -Where ("CardId = `'"+$_.CardId+"`'")
  if($record){
    Update-Trello -Connection $conn -Table Cards -Columns @("Name","ListId") -Values @($_.Name, $_.ListId) -Where "CardId  = `'$_.CardId`'"
  }else{
    Add-Trello -Connection $conn -Table Cards -Columns @("Name","ListId") -Values @($_.Name, $_.ListId)
  }
}

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930