Reputation: 111
For query I use QB WebKit, so my queries look like as:
$customer = new QuickBooks_Object_Customer();
$customer->set(...);
return QBXML_START . $customer->asQBXML('CustomerQueryRq') . QBXML_END;
But for iterators methods it doesn't work. And so I use plaintext method:
return '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="5.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq requestID="' . $requestID . '" iterator="'. $iterator .'">
<MaxReturned>5</MaxReturned>
<OwnerID>0</OwnerID>
</CustomerQueryRq>
</QBXMLMsgsRq>
</QBXML>';
This method return error if MaxReturned < then in Book.
Please, help me write correct query for iterator import data from Quickbooks.
Upvotes: 2
Views: 753
Reputation: 28032
You are correct - the QuickBooks_Object_Customer class will not work with iterators. You'll have to build your own qbXML requests.
With that said, this is all done for you in one of the examples included with the DevKit.
Go grab a nightly release of the QuickBooks PHP DevKit.
Look at this file: docs/example_web_connector_import.php
The code should look something like this:
/**
* Build a request to import customers already in QuickBooks into our application
*/
function _quickbooks_customer_import_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
// Iterator support (break the result set into small chunks)
$attr_iteratorID = '';
$attr_iterator = ' iterator="Start" ';
if (empty($extra['iteratorID']))
{
// This is the first request in a new batch
$last = _quickbooks_get_last_run($user, $action);
_quickbooks_set_last_run($user, $action); // Update the last run time to NOW()
// Set the current run to $last
_quickbooks_set_current_run($user, $action, $last);
}
else
{
// This is a continuation of a batch
$attr_iteratorID = ' iteratorID="' . $extra['iteratorID'] . '" ';
$attr_iterator = ' iterator="Continue" ';
$last = _quickbooks_get_current_run($user, $action);
}
// Build the request
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="' . $version . '"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerQueryRq ' . $attr_iterator . ' ' . $attr_iteratorID . ' requestID="' . $requestID . '">
<MaxReturned>25</MaxReturned>
<FromModifiedDate>' . $last . '</FromModifiedDate>
<OwnerID>0</OwnerID>
</CustomerQueryRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
/**
* Handle a response from QuickBooks
*/
function _quickbooks_customer_import_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
if (!empty($idents['iteratorRemainingCount']))
{
// Queue up another request
$priority = 10;
$Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
$Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, null, $priority, array( 'iteratorID' => $idents['iteratorID'] ));
}
... do stuff with the data you got back here ...
Upvotes: 3