The QuickBooks Online PHP 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 the available report endpoints, and their query parameters, supported by the PHP SDK. You need this information to complete your implementation.
1. Reference the SDK Classes
Include the following require_once
statements:
1 2 3 4 5 | <?php require_once(PATH_SDK_ROOT.'Core/ServiceContext.php'); require_once(PATH_SDK_ROOT.'PlatformService/PlatformService.php'); require_once(PATH_SDK_ROOT.'Utility/Configuration/ConfigurationManager.php'); ?> |
2. Build the ServiceContext object
The ServiceContext
object is a parameter for all calls to QuickBooks Online Data Services, Platform Services, and Reporting Services. When you call a Data Services resource to access QuickBooks Online data, the SDK first retrieves the available custom configuration settings to build the
ServiceContext
object.
OAuthRequestValidator
object. A valid OAuthRequestValidator
object ensures that the end user has authorized your app to access QuickBooks Online data. The following code creates an OAuthRequestValidator
object:
1 2 3 4 5 6 7 8 9 | <?php $accessToken = ''; $accessTokenSecret = ''; $consumerKey = ''; $consumerSecret = ''; $requestValidator = new OAuthRequestValidator( $accessToken, $accessTokenSecret, $consumerKey, $consumerSecret); ?> |
ServiceContext
class:
1 2 3 4 5 | <?php $realmId = ''; $serviceType= IntuitServicesType::QBD; $serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator); ?> |
3. Create the ReportService object
Create an instance of ReportService
by passing the ServiceContext
created in Step 2 as the argument:
1 2 3 | <?php $reportService = new ReportService($serviceContext); ?> |
4. Create report query parameters
Pass all query parameters needed for the particular report to the report service object. For example, the following sets StartDate
, EndDate
, and AccountingMethod
for the Profit and Loss report:
1 2 3 4 5 | <?php $reportService->setStartDate("2015-01-01"); $reportService->setEndDate("2015-02-01"); $reportService->setAccountingMethod("Accrual"); ?> |
5. Execute the report
Execute the report by passing the report name as the attribute to the executeReport
method. Consult this table for a list of available reports. Supported report names are defined in the ReportName.php
file:
1 2 3 | <?php $profitAndLossReport = $reportService->executeReport(ReportName::PROFITANDLOSS); ?> |