Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Query QuickBooks Online Data Using the OData SDK for PHP
You can use the API Server and the OData PHP SDK to easily consume QuickBooks Online entities in PHP by modeling them as objects.
The CData API Server, when paired with the ADO.NET Provider for QuickBooks Online, exposes QuickBooks Online data (or data from any of 200+ other ADO.NET Providers) as Web services. You can follow the procedure below to work with QuickBooks Online data as PHP objects.
About QuickBooks Online Data Integration
CData provides the easiest way to access and integrate live data from QuickBooks Online. Customers use CData connectivity to:
- Realize high-performance data reads thanks to push-down query optimization for complex operations like filters and aggregations.
- Read, write, update, and delete QuickBooks Online data.
- Run reports, download attachments, and send or void invoices directly from code using SQL stored procedures.
- Connect securely using OAuth and modern cryptography, including TLS 1.2, SHA-256, and ECC.
Many users access live QuickBooks Online data from preferred analytics tools like Power BI and Excel, directly from databases with federated access, and use CData solutions to easily integrate QuickBooks Online data with automated workflows for business-to-business communications.
For more information on how customers are solving problems with CData's QuickBooks Online solutions, refer to our blog: https://www.cdata.com/blog/360-view-of-your-customers.
Getting Started
Set Up the API Server
Follow the steps below to begin producing secure QuickBooks Online OData services:
Deploy
The API Server runs on your own server. On Windows, you can deploy using the stand-alone server or IIS. On a Java servlet container, drop in the API Server WAR file. See the help documentation for more information and how-tos.
The API Server is also easy to deploy on Microsoft Azure, Amazon EC2, and Heroku.
Connect to QuickBooks Online
After you deploy the API Server and the ADO.NET Provider for QuickBooks Online, provide authentication values and other connection properties needed to connect to QuickBooks Online by clicking Settings -> Connections and adding a new connection in the API Server administration console.
QuickBooks Online uses the OAuth authentication standard. OAuth requires the authenticating user to log in through the browser. To authenticate using OAuth, you can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL or you can obtain your own by registering an app with Intuit. Additionally, if you want to connect to sandbox data, set UseSandbox to true.
See the Getting Started chapter of the help documentation for a guide to using OAuth.
You can then choose the QuickBooks Online entities you want to allow the API Server access to by clicking Settings -> Resources.
Additionally, configure the API Server for compatibility with the OData SDK for PHP: Click Server -> Settings and in the OData section set Default Version to 2.0.
Authorize API Server Users
After determining the OData services you want to produce, authorize users by clicking Settings -> Users. The API Server uses authtoken-based authentication and supports the major authentication schemes. You can authenticate as well as encrypt connections with SSL. Access can also be restricted based on IP address; by default, only connections from the local machine are allowed.
For simplicity, we will authenticate to the API Server by setting the authtoken in the URL. This is not enabled by default; you will need to add the following lines to the API Server configuration file, settings.cfg.
[Application]
AllowAuthTokenInUrl = true
The settings.cfg file is located in the data directory. In the .NET edition, the data directory is the app_data folder under the www folder. In the Java edition, the data directory's location depends on the operation system:
- Windows: C:\ProgramData\CData\QuickBooksOnline\
- Unix or Mac OS X: ~/cdata/QuickBooksOnline/
Work with QuickBooks Online Entities as PHP Objects
Follow the steps below to use the ODataPHP SDK to create a proxy class that will connect to the Web services exposed by the API Server.
-
Pass the URL to a command like the one below:
php C:\PHPLib\ODataphp\PHPDataSvcUtil.php /uri=https://your-server:8032/api.rsc/@your-authtoken/ /out=C:\PHPLib\ODataphp\QuickBooksOnlineEntities.php
The preceding command defines classes from the metadata returned in the response from the OData endpoint, then outputs the class definitions to the specified folder.
Both the API Server and the OData SDK for PHP support forms and Windows authentication. The API Server uses authtokens to authenticate users authorized to access the OData endpoint. You can supply authtokens in HTTP Basic authentication or append them to the OData URL.
You can configure authorized users in the Settings -> Users section of the API Server administration console.
-
You can now start accessing QuickBooks Online data using an object-oriented interface in PHP. The code below creates a record of the Customers table and then retrieves the live data, showing the newly created record.
require_once 'QuickBooksOnlineEntities.php'; try{ $svc = new CData(); $customers = new Customers(); $customers->FullyQualifiedName = 'Cook, Brian'; $svc->AddToCustomers($customers); $svc->SetSaveChangesOptions(SaveChangesOptions::None); $svc->SaveChanges(); $response = $svc->customers()->Execute(); foreach($response->Result as $customers) echo $customers->DisplayName.""; } catch (Exception $e) { //catch errors from the API Server echo $e->getError(), "\n"; }