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

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

@{
    ViewBag.Title = "GetAllVendor";
}

<h2>Quickbooks online Vendor List</h2>

<div>
    <table class="table table-bordered">
        <tr>
            <th>QBO ID</th>
            <th>Display Name</th>
            <th>Given Name</th>
            <th>Family Name</th>
            <th>Email</th>
            <th>Primary Phone</th>
        </tr>

        @foreach (var Ven in Model)
        {
            <tr>
                <td>@Ven.Id</td>
                <td>@Ven.DisplayName</td>
                <td>@Ven.GivenName</td>
                <td>@Ven.FamilyName</td>
                @if (Ven.PrimaryEmailAddr != null && !string.IsNullOrEmpty(Ven.PrimaryEmailAddr.Address))
                {
                    <td>@Ven.PrimaryEmailAddr.Address</td>
                }
                else
                {
                    <td></td>
                }

                @if (Ven.PrimaryPhone != null && !string.IsNullOrEmpty(Ven.PrimaryPhone.FreeFormNumber))
                {
                    <td>@Ven.PrimaryPhone.FreeFormNumber</td>
                }
                else
                {
                    <td></td>
                }

            </tr>
        }

    </table>
</div>
  • We can also write a query according to our requirements, as like below
string EXISTING_VENDOR_QUERYBYID = string.Format("select * from Vendor where DisplayName = '{0}'", "Tabish VENDOR");
Vendor objVendorFound = queryService.ExecuteIdsQuery(EXISTING_VENDOR_QUERYBYID).FirstOrDefault<Vendor>();
  • it will return a vendor by DisplayName.
  • We will get a vendor which DisplayName=”Tabish VENDOR” in the objVendorFound object.

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

Output: