I am trying to use the DevKit to go through all existing customers in my QuickBooks Online account and update the display name for each one of them to prepend their company name with the company Id I have assigned them. Currently, there are about 1800 customers in the account.
Using the code below, I can successfully process exactly 100 of the customers each time I run the script, but it stops at this point. Is there some time or number limit to the rows return by the Service Customer query? If so, is there a way to increase it? Or is the problem something else entirely?
Quickbooks_update:
class Quickbooks_Update extends CI_Controller
{
function quickbooks_add(){
require_once 'application/QuickBooks/config.php';
$this->load->model('companyAccounts');
$success = array();
$failed = array();
$duplicate = array();
$not_exist = array();
$CustomerService = new QuickBooks_IPP_Service_Customer();
$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer ");
foreach($customers as $customer) {
$name = $customer->getCompanyName();
$q = $this->db->select('companyAccountId');
$q = $this->db->from('companyAccounts');
$q = $this->db->where('companyName', $name);
$q = $this->db->get();
$results = $q->result();
foreach($results as $company){
$companyId = $company->companyAccountId;
}
if(sizeof($results) == 1){
$customer->setDisplayName($companyId . '-' . $name);
$resp = $CustomerService->update($Context, $realm, $customer->getId(), $customer);
if(!$resp){
array_push($failed, $name);
}else{
array_push($success, $name);
}
}
else if(sizeof($results) == 0){
array_push($not_exist, $name);
}
else{
array_push($duplicate, $name);
}
}
$data['success'] = $success;
$data['failed'] = $failed;
$data['duplicate'] = $duplicate;
$data['not_exist'] = $not_exist;
$this->load->view('quickbooks', $data);
}
}
Thank you!
QuickBooks Online by default only returns 100 rows at a time.
If you refer to the documentation:
https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/querying_data
You'll find a bunch of examples of how to use
STARTPOSITION
andMAXRESULTS
to control how many records you get back:SELECT * FROM Invoice WHERE Status = 'Synchronized'STARTPOSITION 1 MAXRESULTS 10
SELECT * FROM Invoice WHERE Status = 'Synchronized'STARTPOSITION 11 MAXRESULTS 10
To quote the documentation:
And: