How To Get Bills From Quickbooks Online Using C#

In this article, we will learn how to get bills from Quickbooks online in .NET MVC web application using SDK.

Before using any Quickbooks online API we need access token, if you don’t know how to get access token then you can find it here.

  • First, we have to create a ServiceContext with Auth tokens and realmId.
  • For that, we need access token and realmId
  • For getting bills, we have to define a QueryService object.
  • QueryService object needs a ServiceContext object as parameter.
  • So we have to create a Quickbooks QueryService using ServiceContext.
  • Here we are getting all bills from Quickbooks online, code is as below.
public ActionResult GetAllBills()
  List<Bill> BillList = new List<Bill>();
      OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(Access_token);
      // Create a ServiceContext with Auth tokens and realmId
      ServiceContext serviceContext = new ServiceContext(RealmId, IntuitServicesType.QBO, oauthValidator);
      serviceContext.IppConfiguration.MinorVersion.Qbo = "23";
      serviceContext.IppConfiguration.BaseUrl.Qbo = QboBaseUrl;

      // Create a QuickBooks QueryService using ServiceContext
      QueryService<Bill> querySvc = new QueryService<Bill>(serviceContext);
      BillList = querySvc.ExecuteIdsQuery("SELECT * FROM bill").ToList();

      return View(BillList);
  catch (IdsException ex)
      return View(BillList);
  catch (Exception ex)
      return View(BillList);
  • We will get all the bill list in the BillList object.
  • View Code is as below,
@model List<Intuit.Ipp.Data.Bill>

    ViewBag.Title = "GetAllBills";

<h2>Quickbooks online Bill List</h2>

    <table class="table table-bordered">
            <th>QBO Bill ID</th>
            <th>Bill Number</th>
            <th>Bill Date</th>
            <th>Total Amount</th>

        @foreach (var item in Model)

  • We can also write a query according to our requirements, as like below
string EXISTING_BILL_QUERYBYID = string.Format("select * from bill where id = '{0}'", "154");
Bill objBillFound = queryService.ExecuteIdsQuery(EXISTING_BILL_QUERYBYID).FirstOrDefault<Bill>();
  • it will return a bill by id.
  • We will get a bill which id=”154” in the objBillFound object.

So that’s how we can get Bills or query Bills from Quickbooks online.


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories