0

Goal: We are attempting to get all transactions once an hour out of QuickBooks Desktop for Windows using QuickBooks Web Connector.

Status: QuickBooks Web Connector runs successfully with the configured qwc file.

Issue: QuickBooks Web Connector returns a green message 'No Data Exchange Required'. I am expecting transactions to be stored in log.txt. Below is my code. I suspect this is a queing issue?. I would like all queing to be in this file that runs every hour in QBWC to get all transactions. Any assistance you can provide would be greatly appreciated.

//web_connector.php - called every 60 min from QBWC
$map = array(
    '*' => array( '_quickbooks_get_transactions', '_quickbooks_get_transactions_response' ),
);

$log_level = QUICKBOOKS_LOG_DEVELOP;
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
$handler_options = array(
    'deny_concurrent_logins' => false, 
    'deny_reallyfast_logins' => false, 
);
$dsn = 'mysqli://'.$dbUser.':'.$dbPass.'@localhost/'.$dbName;
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);
}

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

function _quickbooks_get_transactions($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
//I want to get all transactions from this QuickBooks file and then insert into a database table on my cloud server.
    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <TransactionQuery requestID="' . $requestID . '">

                </TransactionQuery>
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}

function _quickbooks_get_transactions_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{   
    //I want to get all transactions from this QuickBooks file and then insert into a database table on my cloud server.
    //store returned data in text file for testing
    $fp = fopen('log.txt', 'a+');
    fwrite($fp, $xml);
    fclose($fp);
    return;
}
Paul G
  • 1

1 Answers1

0

That message means exactly what it says:

There's no data to exchange. There's nothing to do.

The Web Connector and this framework work using a 'queue' concept. Once the queue is empty, there's nothing else to do, and you'll get that message. If you add something to the queue, then it will process those items until there's nothing left to do, and then you'll get the “No Data Exchange…” message again.

You haven't added anything to the queue.

You could do this with a cron job, or by registering a function that runs whenever the Web Connector connects, and immediately stuffs something in the queue. e.g.:

// An array of callback hooks
$hooks = array(
    QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess',     // call this whenever a successful login occurs
    );

/**
 * Login success hook - perform an action when a user logs in via the Web Connector
 */
function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
    // For new users, we need to set up a few things
    // Fetch the queue instance
    $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();

    $Queue->enqueue(QUICKBOOKS_IMPORT_TRANSACTION);
}

You can see an extended example of this here:

Some other things you may want to take away from the example:

  • With larger data sets, you won't be able to query all of the transactions in just a single request. You can use iterators as shown in the GitHub example to page the records 25 or 100 at a time for better performance/reliability.
  • Use the highest qbXML version your QuickBooks supports (you're using <?qbxml version="2.0"?>)
Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105