Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate QuickBooks Online Integration Tasks from PowerShell
Are you in search of a quick and easy way to access QuickBooks Online data from PowerShell? This article demonstrates how to utilize the QuickBooks Online Cmdlets and the CData ADO.NET Provider for QuickBooks Online for tasks like connecting to QuickBooks Online data, automating operations, downloading data, and more.
The CData Cmdlets for QuickBooks Online 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 QuickBooks Online.
PowerShell Cmdlets or ADO.NET Driver?
The Cmdlets are not only a PowerShell interface to QuickBooks Online, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete QuickBooks Online data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for QuickBooks Online. To access QuickBooks Online data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for QuickBooks Online.
Once you have acquired the necessary connection properties, accessing QuickBooks Online data in PowerShell can be enabled in three steps.
QuickBooks Online uses the OAuth authentication standard. OAuth requires the authenticating user to log in through the browser. To authenticate using OAuth, you can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL or you can obtain your own by registering an app with Intuit. Additionally, if you want to connect to sandbox data, set UseSandbox to true.
See the Getting Started chapter of the help documentation for a guide to using OAuth.
PowerShell
-
Install the module:
Install-Module QuickBooksOnlineCmdlets
-
Connect:
$quickbooksonline = Connect-QBOnline
-
Search for and retrieve data:
$fullyqualifiedname = "Cook, Brian" $customers = Select-QBOnline -Connection $quickbooksonline -Table "Customers" -Where "FullyQualifiedName = `'$FullyQualifiedName`'" $customers
You can also use the Invoke-QBOnline cmdlet to execute SQL commands:
$customers = Invoke-QBOnline -Connection $quickbooksonline -Query 'SELECT * FROM Customers WHERE FullyQualifiedName = @FullyQualifiedName' -Params @{'@FullyQualifiedName'='Cook, Brian'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for QuickBooks Online\lib\System.Data.CData.QuickBooksOnline.dll")
-
Connect to QuickBooks Online:
$conn= New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the QuickBooksOnlineDataAdapter, execute an SQL query, and output the results:
$sql="SELECT DisplayName, Balance from Customers" $da= New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.displayname $_.balance }
Update QuickBooks Online Data
PowerShell
Update-QBOnline -Connection $QuickBooksOnline -Columns @('DisplayName','Balance') -Values @('MyDisplayName', 'MyBalance') -Table Customers -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineCommand("UPDATE Customers SET FullyQualifiedName='Cook, Brian' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.QuickBooksOnline.QuickBooksOnlineParameter("@myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
Insert QuickBooks Online Data
PowerShell
Add-QBOnline -Connection $QuickBooksOnline -Table Customers -Columns @("DisplayName", "Balance") -Values @("MyDisplayName", "MyBalance")
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineCommand("INSERT INTO Customers (FullyQualifiedName) VALUES (@myFullyQualifiedName)", $conn)
$cmd.Parameters.Add(new System.Data.CData.QuickBooksOnline.QuickBooksOnlineParameter("@myFullyQualifiedName","Cook, Brian"))
$cmd.ExecuteNonQuery()
Delete QuickBooks Online Data
PowerShell
Remove-QBOnline -Connection $QuickBooksOnline -Table "Customers" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.QuickBooksOnline.QuickBooksOnlineParameter("@myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
CodeProject