![]() |
VOOZH | about |
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.
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, 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, specify the AccountId connection property. This can be copied from the URL after you log in.
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'}
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 -Connection $Basecamp -Columns @('Name','DocumentsCount') -Values @('MyName', 'MyDocumentsCount') -Table Projects -Id "MyId"
$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()
Add-Basecamp -Connection $Basecamp -Table Projects -Columns @("Name", "DocumentsCount") -Values @("MyName", "MyDocumentsCount")
$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()
Remove-Basecamp -Connection $Basecamp -Table "Projects" -Id "MyId"
$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
Download a free trial of the Basecamp Data Provider to get started:
Download NowLearn more:
👁 Basecamp IconRapidly create and deploy powerful .NET applications that integrate with Basecamp data including Projects, People, Documents, Messages, and more!