Search code examples
phpapisoapquickbooksintuit-partner-platform

Authentication Failed - Web Connector (Consolibyte PHP Quickbooks integration)


I'm trying to establish a connection to our webapp with quickbooks desktop through web connector. However, when I try updating through web connector, I'm getting authentication failed message. We're using consolibyte's quickbooks PHP integration and simply trying to get the example_web_connector_minimal.php file to work.

Here is our .qwc file

<?xml version="1.0"?>
<QBWCXML>
  <AppName>PNW-SS</AppName>
  <AppID></AppID>
  <AppURL>https://beta.helphog.com/quickbooks-php/docs/web_connector/example_web_connector_minimal.php</AppURL>
  <AppDescription>Gateway to WebApp</AppDescription>
  <AppSupport>https://beta.helphog.com</AppSupport>
  <UserName>quickbooks</UserName>
  <OwnerID>{A9A83089-7DA7-4d27-A08C-7E1626E9395A}</OwnerID>
  <FileID>{AE931E67-4AA5-4374-A32D-8EA4BEC91981}</FileID>
  <QBType>QBFS</QBType>
  <Scheduler>
    <RunEveryNMinutes>1</RunEveryNMinutes>
  </Scheduler>
  <IsReadOnly>false</IsReadOnly>
</QBWCXML>

Here's the respective PHP file

<?php

/**
 * Example QuickBooks Web Connector web service
 * 
 * This is a minimal example of using the QuickBooks Web Connector. Make sure 
 * you look at docs/example_web_connector.php for more details. 
 * 
 * MAKE SURE YOU READ OUR QUICK-START GUIDE:
 *  http://wiki.consolibyte.com/wiki/doku.php/quickbooks_integration_php_consolibyte_webconnector_quickstart
 *  http://wiki.consolibyte.com/wiki/doku.php/quickbooks
 * 
 * @author Keith Palmer <[email protected]>
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */

// I always program in E_STRICT error mode... 
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);

// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
    // List of valid timezones is here: http://us3.php.net/manual/en/timezones.php
    date_default_timezone_set('America/New_York');
}

// Require the framework
require_once '../../QuickBooks.php';

// A username and password you'll use in: 
//  a) Your .QWC file
//  b) The Web Connector
//  c) The QuickBooks framework
$user = 'quickbooks';
$pass = 'password';

// Map QuickBooks actions to handler functions
$map = array(
    QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
    // ... more action handlers here ...
    );

// This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
$errmap = array();

// An array of callback hooks
$hooks = array();

// Logging level
$log_level = QUICKBOOKS_LOG_DEVELOP;        // Use this level until you're sure everything works!!!

// * MAKE SURE YOU CHANGE THE DATABASE CONNECTION STRING BELOW TO A VALID MYSQL USERNAME/PASSWORD/HOSTNAME *
$dsn = 'mysql://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

if (!QuickBooks_Utilities::initialized($dsn))
{
    // Initialize creates the neccessary database schema for queueing up requests and logging
    QuickBooks_Utilities::initialize($dsn);
    
    // This creates a username and password which is used by the Web Connector to authenticate
    QuickBooks_Utilities::createUser($dsn, $user, $pass);
    
    // Queueing up a test request
    $primary_key_of_your_customer = 5;
    $Queue = new QuickBooks_WebConnector_Queue($dsn);
    $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}

// Create a new server and tell it to handle the requests
// __construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
$Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level);
$response = $Server->handle(true, true);

/**
 * Generate a qbXML response to add a particular customer to QuickBooks
 */
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    // We're just testing, so we'll just use a static test request:
     
    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerAddRq requestID="' . $requestID . '">
                    <CustomerAdd>
                        <Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>
                        <CompanyName>ConsoliBYTE, LLC</CompanyName>
                        <FirstName>Keith</FirstName>
                        <LastName>Palmer</LastName>
                        <BillAddress>
                            <Addr1>ConsoliBYTE, LLC</Addr1>
                            <Addr2>134 Stonemill Road</Addr2>
                            <City>Mansfield</City>
                            <State>CT</State>
                            <PostalCode>06268</PostalCode>
                            <Country>United States</Country>
                        </BillAddress>
                        <Phone>860-634-1602</Phone>
                        <AltPhone>860-429-0021</AltPhone>
                        <Fax>860-429-5183</Fax>
                        <Email>[email protected]</Email>
                        <Contact>Keith Palmer</Contact>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBXMLMsgsRq>
        </QBXML>';
    
    return $xml;
}

/**
 * Receive a response from QuickBooks 
 */
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
    return; 
}

As stated before, web connector throws this error: enter image description here

And when we open up to see the log in VERBOSE, the following is stated:

20220916.21:39:28 UTC   : QBWebConnector.WebServiceManager.DoUpdateSelected() : updateWS() for application = 'PNW-SS' has STARTED
20220916.21:39:28 UTC   : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
20220916.21:39:28 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
20220916.21:39:28 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: PNW-SS
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): PNW-SS
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: https://beta.helphog.com/quickbooks-php/docs/web_connector/example_web_connector_minimal.php
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.3.0.215">
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'PNW-SS', username = 'quickbooks'
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="quickbooks"><password=<MaskedForSecurity>
20220916.21:39:28 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
Response is not well-formed XML.
More info:
StackTrace =    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at QBWebConnector.localhost.WCWebServiceDoc.authenticate(String strUserName, String strPassword)
   at QBWebConnector.localhost.WCWebService.authenticate(String strUserName, String strPassword)
   at QBWebConnector.SOAPWebService.authenticate(String UserName, String Password)
   at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = System.Web.Services
20220916.21:39:28 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to False
20220916.21:39:28 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session unlocked *********************
20220916.21:39:28 UTC   : QBWebConnector.WebServiceManager.DoUpdateSelected() : Update completed with errors. See log (QWClog.txt) for details.

I'm not quite sure how else I'm supposed to format the XML or if that is even the issue.

When visiting the endpoint in browser:

<br />
<b>Deprecated</b>:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in <b>/home/regiuzkk/beta.helphog.com/quickbooks-php/QuickBooks/Driver/Sql/Mysql.php</b> on line <b>289</b><br />
<br />
<b>Deprecated</b>:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in <b>/home/regiuzkk/beta.helphog.com/quickbooks-php/QuickBooks/Driver/Sql/Mysql.php</b> on line <b>289</b><br />
QuickBooks PHP DevKit Server v3.0 at /quickbooks-php/docs/web_connector/example_web_connector_minimal.php
   (c) "Keith Palmer" <[email protected]> 
   Visit us at: http://www.ConsoliBYTE.com/ 

Use the QuickBooks Web Connector to access this SOAP server.

QuickBooks_WebConnector_Server::handle() parameters: 
 - $return = 1
 - $debug  = 1

Misc. information: 
 - Logging: 4
 - Timezone: America/New_York (Auto-set: )
 - Current Date/Time: 2022-09-16 17:50:07
 - Error Reporting: 32767

SOAP adapter: 
 - QuickBooks_Adapter_Server_Builtin

Registered handler functions: 
Array
(
    [0] => __construct
    [1] => authenticate
    [2] => sendRequestXML
    [3] => receiveResponseXML
    [4] => connectionError
    [5] => getLastError
    [6] => closeConnection
    [7] => serverVersion
    [8] => clientVersion
)

Detected input: 


Timestamp: 
 - 2022-09-16 17:50:07 -- process 0.0365

There are no other errors in the PHP errorlog

Thanks!


Solution

  • As Jacob pointed out, PHP versions differ in their XML format. The version of PHP I was using (5.6), had an outdated XML format therefore an update to PHP version 7.2 was required.