Connect to QuickBooks Online in .NET With C#

QuickBooks Online is one of the top cloud-based accounting solutions, which helps businesses manage their financial operations, track income and expenses, invoice clients, and generate financial reports. This guide will show you how easy it is to establish a secure connection to QuickBooks Online from a C# application using our specialized ADO.NET data provider called dotConnect for QuickBooks Online.

Why dotConnect for QuickBooks Online?

dotConnect for QuickBooks Online is a high-performance ADO.NET data provider that helps access and manage QuickBooks data through the standard ADO.NET or using ORM.

The entire dotConnect product line uses the standard, familiar ADO.NET classes. This helps you get started quickly and eliminates the need to study any specifics or APIs of data sources. With dotConnect, you get easy and secure connections, advanced ORM support, broad compatibility with .NET, and full support for SQL queries that will make your data retrieval and management extremely simple.

Prerequisites

To get started, you will need the following prerequisites:

  • Visual Studio 2022: The most comprehensive IDE for .NET and C++ developers on Windows. If you don't have it on your machine yet, you can download and install the free Community Edition.
  • QuickBooks Online account: You will need credentials for an active QuickBooks account that you are going to connect to.
  • dotConnect for QuickBooks Online: Our data provider will help you connect to your QuickBooks account. It is available for a free 30-day trial. You can either download it from our website or install it as a NuGet package in Visual Studio.

Download and activate dotConnect for QuickBooks Online

30-day free trial

You can download and install dotConnect for QuickBooks Online directly from our website. Alternatively, you can install the Devart.Data.QuickBooks NuGet package in Visual Studio.

No license key is required, and you can start exploring the product immediately.

Full version

After purchasing the full version, go to your profile's Licenses page. Choose your product and click Details. Here, you'll find the license details and the Activation Key.

License details and the Activation Key

To activate a connection in your application, add the License Key to your connection string.

Create a project

1. To create a new C# project, open Visual Studio and select Create a new project in the Get started section.

Create a new project


2. Find the Console App (.NET Framework) template for C#, select it, and click Next.

Create a console app


3. Give it a name and specify a path to the directory it will be stored in. After that, click Create.

Configure your new project


4. Once it's ready, you can proceed to install dotConnect for QuickBooks Online via the NuGet Package Manager. You can do it directly in Visual Studio. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

Manage NuGet Packages for Solution


5. In the NuGet Package Manager that opens, find Devart.Data.QuickBooks and install it for your project.

NuGet Package Mananger

Set up a QuickBooks workspace and create an app

Go to Intuit Developer, log in to your account, and create a new workspace if you don't have one.

Open a QuickBooks workspace


Next, create a new app in your workspace.

Create an app in your QuickBooks workspace


Enter the name of your app.

Enter the app name


Once your app is ready, you will be able to get the credentials required for the connection.

Show credentials

Get QuickBooks credentials

Now you can proceed to your OAuth 2.0 Playground. Select your workspace and app.

Select your workspace and app


Next, you will see your Client ID and Client Secret. Click Get authorization code.

Get authorization code


You will be prompted to approve the connection to your application. To do that, click Connect.

Approve the connection


Next, click Get tokens.

Get tokens


And finally, the last thing you will need to get connected is the refresh token.

Get refresh token


For more detailed guidance, we suggest you visit Intuit's official Get started documentation page.

Establish the connection

After taking the previous steps, you will have everything you need to establish a connection. Here is the sample code that will help you connect to QuickBooks Online. Complete it with the following credentials: Client Id, Company Id, Client Secret, Refresh token, and License key. Additionally, set Sandbox to true if you are using the sandbox application type.

string connectionString = "Sandbox=true;" +
                      	"Client Id=**********;" +
                      	"Company Id=**********;" +
                      	"Client Secret=**********;" +
                      	"Refresh token=**********;" +
                      	"License key=**********;";

This is what our entire application code looks like.

using System;
using System.Data;
using Devart.Data.QuickBooks;

namespace QuickBooksConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Define the connection string
            string connectionString = "Sandbox=true;" +
                                    "Client Id=**********;" +
                                    "Company Id=**********;" +
                                    "Client Secret=**********;" +
                                    "Refresh token=**********;" +
                                    "License key=**********;";

            try
            {
                // Initialize the QuickBooks connection
                using (QuickBooksConnection quickBooksConnection = new QuickBooksConnection())
                {
                    quickBooksConnection.ConnectionString = connectionString;

                    // Open the connection
                    quickBooksConnection.Open();

                    Console.WriteLine("Connected to QuickBooks Online successfully.");

                    // Define the SQL query to fetch data from the Account table
                    string query = "SELECT Id, Name, FullyQualifiedName, Description FROM Account";

                    // Create a command object
                    using (QuickBooksCommand command = new QuickBooksCommand(query, quickBooksConnection))
                    {
                        // Execute the command and get a data reader
                        using (QuickBooksDataReader reader = command.ExecuteReader())
                        {
                            // Check if data exists
                            if (reader.HasRows)
                            {
                                Console.WriteLine("Fetching Account data:");
                                Console.WriteLine("--------------------------------------------------");

                                // Loop through the data
                                while (reader.Read())
                                {
                                    string id = reader["Id"]?.ToString() ?? "N/A";
                                    string name = reader["Name"]?.ToString() ?? "N/A";
                                    string fullyQualifiedName = reader["FullyQualifiedName"]?.ToString() ?? "N/A";
                                    string description = reader["Description"]?.ToString() ?? "N/A";

                                    Console.WriteLine($"Id: {id}");
                                    Console.WriteLine($"Name: {name}");
                                    Console.WriteLine($"FullyQualifiedName: {fullyQualifiedName}");
                                    Console.WriteLine($"Description: {description}");
                                    Console.WriteLine("--------------------------------------------------");
                                }
                            }
                            else
                            {
                                Console.WriteLine("No data found in the Account table.");
                            }
                        }
                    }

                    // Close the connection
                    quickBooksConnection.Close();
                    Console.WriteLine("Connection closed.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred:");
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

Once you successfully connect your application to QuickBooks Online, you will be able to fetch and manage your data.

Test application connection in Visual Studio

Conclusion

This is how you can connect your own C# application to QuickBooks Online using dotConnect for QuickBooks. From here, you can expand your application to perform various operations, including the following:

  • Query customers, invoices, and accounts
  • Write and update QuickBooks data programmatically

If you want to get some firsthand experience, feel free to download dotConnect for QuickBooks Online for a free 30-day trial and give it a go under the real workload. To help you get started as quickly and easily as possible, we suggest you refer to our documentation, which is replete with useful tips and walkthroughs.

dotConnect for QuickBooks

Get an enhanced ORM-enabled data provider and develop .NET applications working with QuickBooks data quickly and easily!