In this article, we will learn how to get company info 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.

Company info contains basic company information. We can get company info that is currently connected.

Below are a few steps for getting company info,

  • First, we have to create a ServiceContext with Auth tokens and realmId.
  • For that, we need access token and realmId
  • For getting company info, 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 currently connected company info from Quickbooks online, code is as below.
public ActionResult GetCompanyInfo()
{
  CompanyInfo ObjCompanyInfo = new CompanyInfo();
  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;

    var queryService = new QueryService<CompanyInfo>(serviceContext);
    ObjCompanyInfo = queryService.ExecuteIdsQuery("select * from CompanyInfo").FirstOrDefault<CompanyInfo>();

    if (ObjCompanyInfo != null)
    {
        ViewBag.IsSuccess = true;
    }

    return View(ObjCompanyInfo);
  }
  catch (IdsException ex)
  {
    return View(ObjCompanyInfo);
  }
  catch (Exception ex)
  {
    return View(ObjCompanyInfo);
  }
}
  • We will get the company info in the ObjCompanyInfo object.
  • View Code is as below,
@model Intuit.Ipp.Data.CompanyInfo

@{
    ViewBag.Title = "GetCompanyInfo";
}

<h2>Company Info</h2>


@if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true)
{
    <div>
        <table class="table table-bordered">
            <tr>
                <th>Id</th>
                <th>Company Name</th>
                <th>Legal Name</th>
                <th>Country</th>
                <th>Email</th>
            </tr>

            <tr>
                <td>
                    @Model.Id
                </td>
                <td>
                    @Model.CompanyName
                </td>
                <td>
                    @Model.LegalName
                </td>
                <td>
                    @Model.Country
                </td>
                <td>
                    @Model.Email.Address
                </td>
            </tr>

        </table>
    </div>
}

So that’s how we can get company info from Quickbooks online.

Output: