# Initial steps towards successful integration Quickbooks & PHP?

Integration:  PHP and Quickbooks using v3-php-sdk-2.0.5

This was a bit of headache. In this article I explain how to configure your quickbooks php sdk, issues faced, fixes until successful integration.

Some useful references to accomplish php / quickbook integration using the php sdk.
http://bit.ly/IppPhpSdkV3

- PHP SDK for QuickBooks V3 documentation and getting started
https://developer.intuit.com/docs/0100_accounting/0500_developer_kits/0210_ipp_php_sdk_for_quickbooks_v3

*** Trying to Integrate
After download the v3-php-sdk-2.0.5 in order to accomplish the quickbooks integration, i have faced some serious problems to be able to integrate. After the installation I have set some settings in App.Config and directly accessed _Samples folder and decided to run the safest CustomerQuery.php - assuming it doesn’t cause any modification to our existing records :).

Fatal error: Uncaught exception ‘UnexpectedValueException’ with message ‘DirectoryIterator::__construct(/var/folders/bn/gqvb2w4x7n3573t34xd1sdn00000gq/T): failed to open dir: Permission denied’ in /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php:65 Stack trace: #0 /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php(65): DirectoryIterator->__construct('/var/folders/bn…') #1 /Applications/XAMPP/xamppfiles/htdocs/test/v3-php-sdk-2.0.5/Core/RestCalls/SyncRestHandler.php(227): LogRequestsToDisk->LogPlatformRequests(‘SELECT * FROM C…', ‘https://sandbox…', Array, true) #2 /var/www/test/v3-php-sdk-2.0.5/DataService/DataService.php(572): SyncRestHandler->GetResponse(Object(RequestParameters), ‘SELECT * FROM C…', NULL) #3 /var/www/test/v3-php-sdk-2.0.5/_Samples/CustomerQuery.php(37): DataService->Query(‘SELECT * FROM C…') #4 {main} thrown in /var/www/test/v3-php-sdk-2.0.5/Core/LogRequestsToDisk.php on line 65

After tracing the code i found out that the situation is caused by the following setting in sdk.config:

So basically I thought, let’s turn the logging off. The result was still the same after mofifying the configuration:

After tracing the code I discovered that a fix should be applied to overcome this problem.
*** Applied FIX:

/Core/LogRequestsToDisk.php / line 57:
if ($this->EnableServiceRequestsLogging) replaced by if ($this->EnableServiceRequestsLogging == ‘true’)

Description:
EnableServiceRequestsLogging was interpreted as string when using false value and on casting to bool the string word ‘false’ was considered to be true: (bool)‘false’ –> true
After applying this fix we are ready to go and start setting up our configuration and the environment.
*** Quickbooks developer account - Creating an App
The first thing you want to do is to create an app on quickbooks developer account by connecting to which you will be integrating with your quickbooks online account. In order to achieve this, access:
https://developer.intuit.com

From the top right menu, click “My Apps” and then create a new App.

For this tutorial choose the “Just start coding” option on the right and then check “Accounting” out of Quickbooks API. So far you have an app and some keys for development. Now you need to click on the “Keys” tab and you will see the App Token , OAuth Consumer Key and OAuth Consumer Secret.

Basically the idea here is to generate AccessToken and AccessTokenSecret using the existing (App Token , OAuth Consumer Key and OAuth Consumer Secret). This will mean that your application with (App Token) will be granted access to your account data and services and will be authenticated by AccessToken and AccessTokenSecret, that you will use to connect from your application to the SDK.
Integration scenario
PHP CODE + SDK –(connected to)–> Developer Application –(connected to)–> Quickbooks APIs
*** Getting authentication tokens

In order to generate access token for your app to your whole account, you need to do this using the url:
https://appcenter.intuit.com/Playground/OAuth

following step-by step instructions, starting from the already defined App Token , OAuth Consumer Key and OAuth Consumer Secret, we will continue until we get AccessToken and AccessTokenSecret. After this point we have all the authentication tokens we need in order to configure our SDK.
*** Configuration
we need 2 configuration files:
App.Config - located at the path of the index file you are working on
sdk.config - located at the root path of the SDK

App.Config should containg the settings:
- RealmID (your company id, can include the sandbox company id)
- AccessToken
- AccessTokenSecret
- ConsumerKey
- ConsumerSecret
sdk.config should be adjusted:

As we are integrating with quickbooks, we are concerned about “qbo” attribute of “baseUrl”.
In case we are on development environment and would like to use the actual company keys, we would need to use the default url:
https://quickbooks.api.intuit.com/

In case we are connecting to the sandbox company this url has to be changed to:
https://sandbox-quickbooks.api.intuit.com/

Sample App.Config file:

Sample sdk.config file:

If you have any ideas or suggestions or other experiences about PHP - Quickbooks SDK integration please comment below. :)
Happy integration !