QuickBooks php DevKit database query only returning 100 rows

719 views Asked by At

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!

1

There are 1 answers

1
Keith Palmer Jr. On BEST ANSWER

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 and MAXRESULTS 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:

To page through the results, specify STARTPOSITION (position of the entity in the query results) and MAXRESULTS (maximum number of entities in the result).

And:

The maximum number of entities that can be returned in a response is 1000. If the result size is not specified, the default number is 100. If a query returns many entities, fetch the entities in chunks, as described in Pagination. To determine the number of entities that a particular query returns, probe by using the COUNT keyword in the query. See Count for details.