In this article, we will learn how to get items 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 items, 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 items from Quickbooks online, code is as below.
public ActionResult GetAllItem()
{
  List<Item> ItemList = new List<Item>();
  try
  {
    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<Item> querySvc = new QueryService<Item>(serviceContext);
    ItemList = querySvc.ExecuteIdsQuery("SELECT * FROM Item").ToList();

    return View(ItemList);
  }
  catch (IdsException ex)
  {
    return View(ItemList);
  }
  catch (Exception ex)
  {
    return View(ItemList);
  }
}
  • We will get a list of items in the ItemList object.
  • View Code is as below,
@model List<Intuit.Ipp.Data.Item>
@{
    ViewBag.Title = "GetAllItem";
}

<h2>Quickbooks online Item List</h2>

<div>
    <table class="table table-bordered">
        <tr>
            <th>QBO ID</th>
            <th>Item Name</th>
            <th>Account Type</th>
            <th>Sales Description</th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Name</td>
                <td>@item.Type</td>
                <td>@item.Description</td>
            </tr>
        }

    </table>
</div>
  • We can also write a query according to our requirements, as like below
string EXISTING_ITEM_QUERYBYNAME = string.Format("select * from Item where Name = '{0}'", "Vision Keyboard");
Item objItemFound = querySvc.ExecuteIdsQuery(EXISTING_ITEM_QUERYBYNAME).FirstOrDefault<Item>();
  • it will return an item by Name.
  • We will get an item which Name is ”Vision Keyboard” in the objItemFound.

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

Output: