Reports

The QuickBooks Online Java SDK provides methods that wrap the QuickBooks Online Reports API. The following sections describe how to call the methods synchronously. Before proceeding, see Run reports to familiarize yourself with reports and their query parameters.

1. Build the Context object.

The Context object is a parameter for all calls to QuickBooks Online Data Services.

  1. Create an OAuthAuthorizer object. A valid OAuthAuthorizer object ensures that the end-user has authorized your app to access QuickBooks Online data. The following code creates an OAuthAuthorizer object:

1
2
3
String accessToken = ...

OAuth2Authorizer oauth = new OAuth2Authorizer(accessToken);
  1. Create an instance of the Context class. The following code snippet creates a Context object:

1
2
3
4
String appToken = ...
String companyID = ...

Context context = new Context(oauth, appToken, ServiceType.QBO, companyID);

Note

Note

For more information, see Authorization.

2. Create the ReportService object.

Create an instance of ReportService by passing the Context object created in Step 2 as the argument:

1
ReportService service = new ReportService(context);

3. Include the report query parameters.

Include all the desired query parameters to the service object created in Step 2 above:

1
2
3
service.setStart_date("2020-01-01");
service.setEnd_date("2020-03-20");
service.setAccounting_method("Accrual");

4. Execute report.

Execute the report by passing the report name as attribute. Consult this table for a list of available reports. Report names are defined in the ReportName enum:

1
Report report = service.executeReport(ReportName.PROFITANDLOSS.toString());