The QuickBooks Online PHP SDK makes it easy to integrate your PHP web app with the QuickBooks Online API. This guide assumes that you have an existing web app that you want to integrate with QuickBooks Online.
This tutorial includes the following:
Note
Note
This step can be skipped for running the Hello, World! Sample app.
The recommended way to install the QuickBooks PHP SDK is with Composer. Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.
The installation of composer is local by default.
Install Composer ( if not installed )
1 | curl -sS https://getcomposer.org/installer | php |
You can add the SDK as a dependency using the composer.phar CLI:
1 | composer require quickbooks/v3-php-sdk |
1 2 3 4 5 | { "require": { "quickbooks/v3-php-sdk": ">=*" } } |
1 2 3 | <?php require 'vendor/autoload.php'; ?> |
View Screenshot
View Screenshot
View Screenshot
View Screenshot
View Screenshot
View Screenshot
http://localhost:8080/callback.php
. Set the Redirect URI in the Keys & OAuth tab with this URL.View Screenshot
1 2 3 4 5 6 7 8 9 10 | <?php return array( 'authorizationRequestUrl' => 'https://appcenter.intuit.com/connect/oauth2', 'tokenEndPointUrl' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', 'client_id' => 'Enter the clietID from Developer Portal', 'client_secret' => 'Enter the clientSecret from Developer Portal', 'oauth_scope' => 'com.intuit.quickbooks.accounting openid profile email phone address', 'oauth_redirect_uri' => 'http://localhost:8080/callback.php', ) ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php $dataService = DataService::Configure(array( 'auth_mode' => 'oauth2', 'ClientID' => $config['client_id'], 'ClientSecret' => $config['client_secret'], 'RedirectURI' => $config['oauth_redirect_uri'], 'scope' => $config['oauth_scope'], 'baseUrl' => "development" )); $OAuth2LoginHelper = $dataService->getOAuth2LoginHelper(); // Get the Authorization URL from the SDK $authUrl = $OAuth2LoginHelper->getAuthorizationCodeURL(); ?> |
1 2 3 4 5 6 7 8 9 10 | <?php return array( 'authorizationRequestUrl' => 'https://appcenter.intuit.com/connect/oauth2', 'tokenEndPointUrl' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', 'client_id' => 'Enter the clietID from Developer Portal', 'client_secret' => 'Enter the clientSecret from Developer Portal', 'oauth_scope' => 'com.intuit.quickbooks.accounting openid profile email phone address', 'oauth_redirect_uri' => 'http://localhost:8080/callback.php', ) ?> |
View Screenshot
View Screenshot
1 | $parseUrl = parseAuthRedirectUrl($_SERVER['QUERY_STRING']); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php function processCode() { // Create SDK instance $config = include('config.php'); $dataService = DataService::Configure(array( 'auth_mode' => 'oauth2', 'ClientID' => $config['client_id'], 'ClientSecret' => $config['client_secret'], 'RedirectURI' => $config['oauth_redirect_uri'], 'scope' => $config['oauth_scope'], 'baseUrl' => "development" )); $OAuth2LoginHelper = $dataService->getOAuth2LoginHelper(); $parseUrl = parseAuthRedirectUrl($_SERVER['QUERY_STRING']); /* * Update the OAuth2Token */ $accessToken = $OAuth2LoginHelper->exchangeAuthorizationCodeForToken($parseUrl['code'], $parseUrl['realmId']); $dataService->updateOAuth2Token($accessToken); /* * Setting the accessToken for session variable */ $_SESSION['sessionAccessToken'] = $accessToken; } ?> |
Once the tokens are received, tokens can be used to make QuickBooks Online API calls. As you can notice from the sample, we have a script to make API Call, ( apiCall.php) refer screenshot below:
View Screenshot
Since PHP does not provide a way to transfer objects between PHP files, we will retrieve the access/refresh token we stored in the session variable earlier and update the DataService object using the function below.
1 2 3 | <?php $accessToken = $_SESSION['sessionAccessToken']; ?> |
But first, create a DataService object. This DataService object is then used to get CompanyInfo data. Refer to the code here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <?php function makeAPICall() { // Create SDK instance $config = include('config.php'); $dataService = DataService::Configure(array( 'auth_mode' => 'oauth2', 'ClientID' => $config['client_id'], 'ClientSecret' => $config['client_secret'], 'RedirectURI' => $config['oauth_redirect_uri'], 'scope' => $config['oauth_scope'], 'baseUrl' => "development" )); /* * Retrieve the accessToken value from session variable */ $accessToken = $_SESSION['sessionAccessToken']; /* * Update the OAuth2Token of the dataService object */ $dataService->updateOAuth2Token($accessToken); $companyInfo = $dataService->getCompanyInfo(); print_r($companyInfo); return $companyInfo; } $result = makeAPICall(); ?> |
Important
Congratulations
You are all set to develop your app with QuickBooks.