Cmdlets for Asana

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 Asana 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 AsanaCmdlets

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

Import-Module AsanaCmdlets;

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

$conn = Connect-Asana -InitiateoAuth "GETANDREFRESH" -OAuthClientId "YourClientId" -OAuthClientSecret "YourClientSecret" -CallbackURL "http://localhost:33333"

Connecting to Asana

You can optionally set the following to refine the data returned from Asana.

  • WorkspaceId: Set this to the globally unique identifier (gid) associated with your Asana Workspace to only return projects from the specified workspace. To get your workspace id, navigate to while logged into Asana. This displays a JSON object containing your workspace name and Id.
  • ProjectId: Set this to the globally unique identifier (gid) associated with your Asana Project to only return data mapped under the specified project. Project IDs can be found in the URL of your project's Overview page. This will be the numbers directly after /0/.

Connect Using OAuth Authentication

You must use OAuth to authenticate with Asana. OAuth requires the authenticating user to interact with Asana using the browser. For more information, refer to Using OAuth Authentication.

Retrieving Data

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

$results = Select-Asana -Connection $conn -Table "projects" -Columns @("Id, WorkspaceId") -Where "Archived='true'"
The Invoke-Asana 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-Asana -Connection $conn -Table projects -Where "Archived = 'true'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myprojectsData.csv -NoTypeInformation

You will notice that we piped the results from Select-Asana 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-Asana -InitiateoAuth "GETANDREFRESH" -OAuthClientId "YourClientId" -OAuthClientSecret "YourClientSecret" -CallbackURL "http://localhost:33333"
PS C:\> $row = Select-Asana -Connection $conn -Table "projects" -Columns (Id, WorkspaceId) -Where "Archived = 'true'" | select -first 1
PS C:\> $row | ConvertTo-Json
  "Connection":  {

  "Table":  "projects",
  "Columns":  [

  "Id":  "MyId",
  "WorkspaceId":  "MyWorkspaceId"

Deleting Data

The following line deletes any records that match the criteria:

Select-Asana -Connection $conn -Table projects -Where "Archived = 'true'" | Remove-Asana

Updating Data

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

Import-Csv -Path C:\MyprojectsUpdates.csv | %{
  $record = Select-Asana -Connection $conn -Table projects -Where ("Id = `'"+$_.Id+"`'")
    Update-Asana -Connection $conn -Table projects -Columns @("Id","WorkspaceId") -Values @($_.Id, $_.WorkspaceId) -Where "Id  = `'$_.Id`'"
    Add-Asana -Connection $conn -Table projects -Columns @("Id","WorkspaceId") -Values @($_.Id, $_.WorkspaceId)

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