The QuickBooks Online .NET 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 ServiceContext object
A ServiceContext
object is required as a parameter for all calls to QuickBooks Online Data Services. To create a ServiceContext
object:
OAuth2RequestValidator
object, which will be used to create a ServiceContext
object. A valid OAuth2RequestValidator
object ensures that the end-user has authorized your app to access QuickBooks Online data. The following code creates an OAuth2RequestValidator
object:
1 2 3 | String accessToken = ... OAuth2RequestValidator oauth = new OAuth2RequestValidator(accessToken); |
ServiceContext
class. The following code snippet creates the ServiceContext
object:
1 2 3 | String realmId = ... ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauth); |
Note
Note
For more information, see Authorization.
2. Create the ReportService object
Create an instance of ReportService
by passing the serviceContext
object created in the previous step as the argument.
1 | ReportService service = new ReportService(serviceContext); |
3. Include the report query parameters
Include all the desired query parameters for the report of choice to the service object created in Step 2 above.
1 2 3 | service.start_date = "2014-01-01"; service.end_date = "2014-03-20"; service.accounting_method = "Accrual"; |
4. Execute the report
Execute the report by passing the report endpoint as the attribute. Consult this table for a list of endpoints.
1 | Report report = service.ExecuteReport("ProfitAndLoss"); |
Note
Note
To see an example of how to parse a report, see Retrieve report and print to console sample on GitHub.