Query filters

The query filters of the QuickBooks Online .NET SDK enable your app to retrieve entities whose properties meet specified criteria. For example, your app can retrieve only those customer entities that have been created within the last 20 days.

Note

Note

To get the SDK to log the queries, enable request and response logging. For steps, see Request and response logging.

To create a query filter:

  1. Reference the SDK Assemblies

Make sure the following assemblies have been referenced:

Include the following using statements:

1
2
3
4
using Intuit.Ipp.Core;
using Intuit.Ipp.Data;
using Intuit.Ipp.Security;
using Intuit.Ipp.QueryFilter;
  1. Build the ServiceContext

ServiceContext is a parameter for all calls to QuickBooks Online Data Services, Platform Services, and Reporting Services.

  1. Create the OAuth2RequestValidator object:

1
OAuth2RequestValidator reqValidator = new OAuth2RequestValidator(accessToken);
  1. Create an instance of the ServiceContext class.

1
ServiceContext context = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);

Note

Note

For more information, see Authorization and Configuration.

  1. Create the query service

Create an instance of QueryService for an entity by passing the ServiceContext created in Step 2 as the argument.

The following example shows how to create a QueryService instance for customer entity.

1
QueryService<Customer> customerQueryService = new QueryService<Customer>(context);

The following example shows how to create a QueryService instance for Invoice entity.

1
QueryService<Invoice> invoiceQueryService = new QueryService<Invoice>(context);

Now you are ready to create and execute queries. Proceed to the next section.

Create and execute the query

The following example queries the Customer entity. For more details and query examples, see Data queries.

1
2
QueryService<Customer> customerQueryService = new QueryService<Customer>(context);
Customer customer = customerQueryService.ExecuteIdsQuery("Select * From Customer where Id = 1").FirstOrDefault<Customer>();