Connect Workday to your favorite reporting tools without moving data.
Learn More →Automate Basecamp Integration Tasks from PowerShell
Are you looking for a quick and easy way to access Basecamp data from PowerShell? We show how to use the Cmdlets for Basecamp and the CData ADO.NET Provider for Basecamp to connect to Basecamp data and synchronize, automate, download, 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.
Cmdlets or ADO.NET?
The cmdlets are not only a PowerShell interface to the Basecamp API, 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.
After obtaining the needed connection properties, accessing Basecamp data in PowerShell consists of three basic 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("User=test@northwind.db;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 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 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 System.Data.CData.Basecamp.BasecampParameter("@myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
CodeProject