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 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.

About QuickBooks Online Data Integration

CData provides the easiest way to access and integrate live data from QuickBooks Online. Customers use CData connectivity to:

  • Realize high-performance data reads thanks to push-down query optimization for complex operations like filters and aggregations.
  • Read, write, update, and delete QuickBooks Online data.
  • Run reports, download attachments, and send or void invoices directly from code using SQL stored procedures.
  • Connect securely using OAuth and modern cryptography, including TLS 1.2, SHA-256, and ECC.

Many users access live QuickBooks Online data from preferred analytics tools like Power BI and Excel, directly from databases with federated access, and use CData solutions to easily integrate QuickBooks Online data with automated workflows for business-to-business communications.

For more information on how customers are solving problems with CData's QuickBooks Online solutions, refer to our blog: https://www.cdata.com/blog/360-view-of-your-customers.


Getting Started


PowerShell Cmdlets or ADO.NET Provider?

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

  1. Install the module:

    Install-Module QuickBooksOnlineCmdlets
  2. Connect:

    $quickbooksonline = Connect-QBOnline
  3. 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

  1. 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")
  2. Connect to QuickBooks Online:

    $conn= New-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. 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-Object 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-Object 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-Object System.Data.CData.QuickBooksOnline.QuickBooksOnlineParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()

Ready to get started?

Download a free trial of the QuickBooks Online Data Provider to get started:

 Download Now

Learn more:

QuickBooks Online Icon QuickBooks Online ADO.NET Provider

Complete read-write access to QuickBooks Online enables developers to search (Customers, Transactions, Invoices, Sales Receipts, etc.), update items, edit customers, and more, from any .NET application.