QuickBooks Online

How To Get Tax Agencies From Quickbooks Online Using C#

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

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

@{
    ViewBag.Title = "GetAllTaxAgencies";
}

<h2>Quickbooks online Tax Agencies</h2>

<div>
    <table class="table table-bordered">
        <tr>
            <th>QBO ID</th>
            <th>Display Name</th>
        </tr>

        @foreach (var TAItem in Model)
        {
            <tr>
                <td>@TAItem.Id</td>
                <td>@TAItem.DisplayName</td>
            </tr>
        }

    </table>
</div>
  • We can also write a query according to our requirements, as like below
string EXISTING_TAXAGENCY_QUERYBYID = string.Format("select * from TaxAgency where id = '{0}'", "4");
TaxAgency objTaxAgencyFound = queryService.ExecuteIdsQuery(EXISTING_TAXAGENCY_QUERYBYID).FirstOrDefault<TaxAgency>();
  • it will return tax agency by id.
  • We will get a tax agency which id=”4” in the objTaxAgencyFound object.

So that’s how we can get “tax agencies” or query “tax agency”  from Quickbooks online.

Output:

 

Tabish Rangrej

Tabish Rangrej is an Experienced .NET Team Leader, software engineer, and Author with a demonstrated history of working in the IT industry. He has quite well experience in developing, communicating, managing, and writing in his field. He has strong skills and knowledge of ASP.NET C#, ASP.NET MVC, ASP.NET CORE, Angular, AngularJS, Web API, SQL, Entity Framework, JavaScript, Jquery, Different Integrations like Quickbooks, Stripe, Google APIs, Zoho, Orion, Xero, etc., Different versioning tools like TFS, SVN, GIT, etc. and Windows services. Strong engineering professional with a Master of Computer Applications - MCA focused on Computer Science from Veer Narmad South Gujarat University, Surat. Tabish is always ready to accept new challenges and learn new things, he would like to serve better for the community.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago