Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Basecamp Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Basecamp data from PowerShell? This article demonstrates how to utilize the Basecamp Cmdlets for tasks like connecting to Basecamp data, automating operations, downloading data, and more.
The CData Cmdlets for Basecamp are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Basecamp.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Basecamp, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Basecamp data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Basecamp. To access Basecamp data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Basecamp.
Once you have acquired the necessary connection properties, accessing Basecamp data in PowerShell can be enabled in three steps.
Basecamp uses basic or OAuth 2.0 authentication. To use basic authentication you will need the user and password that you use for logging in to Basecamp. To authenticate to Basecamp via OAuth 2.0, you will need to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties by registering an app with Basecamp.
See the Getting Started section in the help documentation for a connection guide.
Additionally, you will need to specify the AccountId connection property. This can be copied from the URL after you log in.
PowerShell
-
Install the module:
Install-Module BasecampCmdlets
-
Connect:
$basecamp = Connect-Basecamp -User "$User" -Password "$Password"
-
Search for and retrieve data:
$drafts = "True" $projects = Select-Basecamp -Connection $basecamp -Table "Projects" -Where "Drafts = `'$Drafts`'" $projects
You can also use the Invoke-Basecamp cmdlet to execute SQL commands:
$projects = Invoke-Basecamp -Connection $basecamp -Query 'SELECT * FROM Projects WHERE Drafts = @Drafts' -Params @{'@Drafts'='True'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Basecamp\lib\System.Data.CData.Basecamp.dll")
-
Connect to Basecamp:
$conn= New-Object System.Data.CData.Basecamp.BasecampConnection("[email protected];Password=test123;") $conn.Open()
-
Instantiate the BasecampDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, DocumentsCount from Projects" $da= New-Object System.Data.CData.Basecamp.BasecampDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.documentscount }
Update Basecamp Data
PowerShell
Update-Basecamp -Connection $Basecamp -Columns @('Name','DocumentsCount') -Values @('MyName', 'MyDocumentsCount') -Table Projects -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.Basecamp.BasecampCommand("UPDATE Projects SET Drafts='True' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Basecamp.BasecampParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Basecamp Data
PowerShell
Add-Basecamp -Connection $Basecamp -Table Projects -Columns @("Name", "DocumentsCount") -Values @("MyName", "MyDocumentsCount")
ADO.NET
$cmd = New-Object System.Data.CData.Basecamp.BasecampCommand("INSERT INTO Projects (Drafts) VALUES (@myDrafts)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Basecamp.BasecampParameter("@myDrafts","True")))
$cmd.ExecuteNonQuery()
Delete Basecamp Data
PowerShell
Remove-Basecamp -Connection $Basecamp -Table "Projects" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.Basecamp.BasecampCommand("DELETE FROM Projects WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Basecamp.BasecampParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject