Cmdlets for Basecamp

Build 20.0.7587

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 Basecamp 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 BasecampCmdlets

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

Import-Module BasecampCmdlets;

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

$conn = Connect-Basecamp -AccountId '1234567' -ProjectId 'abcd1234' -Schema 'V3'

Connecting to Basecamp

In addition to authenticating, set the following connection properties to access Basecamp tables.

  • Schema: Set this to "V2" or "V3" to connect to a Basecamp 2 or Basecamp 3 account.
  • ProjectId: This is a required parameter for most table operations. You can query the Projects table to obtain this value.

    If you do not specify the ProjectId connection property, the cmdlet will use the first project Id returned from the Projects table in your first authentication to Basecamp.

  • AccountId: You can find the AccountId in the URL after you log in to Basecamp in a web browser:<AccountId>

Authenticating to Basecamp

Basecamp 2 uses basic or OAuth 2.0 authentication. You can use basic authentication to connect to your own account, or you can use OAuth to enable other users to log into their own accounts.

Basecamp 3 requires OAuth 2.0.

Authenticate via Basic Authentication

In basic authentication, you use your login credentials to connect. Set the following properties:

  • User: This is the username you use to log in to Basecamp.
  • Password: This is the password you use to log in to Basecamp.

Authenticate via OAuth Authentication

You can connect without setting any connection properties for your user credentials.

When you connect, the cmdlet opens the Basecamp OAuth endpoint in your default browser. Log in and grant permissions to the cmdlet. The cmdlet then completes the following OAuth process:

See Using OAuth Authentication for other OAuth authentication flows.

Retrieving Data

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

$results = Select-Basecamp -Connection $conn -Table "Projects" -Columns @("Id, Name") -Where "Id='MyId'"
The Invoke-Basecamp 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-Basecamp -Connection $conn -Table Projects -Where "Id = 'MyId'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myProjectsData.csv -NoTypeInformation

You will notice that we piped the results from Select-Basecamp 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-Basecamp -AccountId '1234567' -ProjectId 'abcd1234' -Schema 'V3'
PS C:\> $row = Select-Basecamp -Connection $conn -Table "Projects" -Columns (Id, Name) -Where "Id = 'MyId'" | select -first 1
PS C:\> $row | ConvertTo-Json
  "Connection":  {

  "Table":  "Projects",
  "Columns":  [

  "Id":  "MyId",
  "Name":  "MyName"

Deleting Data

The following line deletes any records that match the criteria:

Select-Basecamp -Connection $conn -Table Projects -Where "Id = 'MyId'" | Remove-Basecamp

Updating Data

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

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

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587