// // We're going to query QuickBooks for a customer named "Keith Palmer". // The query will be executed against QuickBooks and the function named // "_quickbooks_ca_customer_getbyname_callback" will be called with an // Iterator object. The Iterator will either be empty (there is no customer by // the name of "Keith Palmer") or contain Keith's complete customer record. // // Pretend for a minute that we actually have "Keith Palmer" in our own web // application, and what we'd really like to do is check if he exists in // QuickBooks, and then create a mapping so we know that Keith's primate key // in our database maps to QuickBooks primary key XYZ. To accomplish this, // we'll call the API method passing in Keith's primary key, so we can create // the mapping later in the callback function. $customers_name = 'Keith Palmer'; $primary_key_of_customer_in_your_application = 15; if ($API->getCustomerByName($customers_name, '_quickbooks_ca_customer_getbyname_callback', $primary_key_of_customer_in_your_application)) { print 'Queued up a request to fetch a customer named "' . $customers_name . '"!' . "\n"; } // Adding a new customer to QuickBooks // // This example shows how to queue up a request to add a new customer to // QuickBooks. Remember that the Name element of a customer is unique within // QuickBooks, and the request will fail and send you back an error message if // another customer in QuickBooks already has that name. $name = 'Shannon\'s Company (' . mt_rand() . ')'; $fname = 'Shannon'; $lname = 'Daniels'; // (the mt_rand() call is just so I don't get duplicate customer errors while testing) $Customer = new QuickBooks_Object_Customer(); // This is a unique name (usually a company name) for the customer $Customer->setName($name);
print 'Our real-time response from QuickBooks Online Edition was: '; print_r($return); } exit; // You can also create QuickBooks_Object_* instances and send them directly to // QBOE via the API as show below. The API takes care of transforming those // objects to valid qbXML requests for you. $name = 'Keith Palmer (' . mt_rand() . ')'; $Customer = new QuickBooks_Object_Customer(); $Customer->setName($name); $Customer->setShipAddress('134 Stonemill Road', '', '', '', '', 'Storrs', 'CT', '', '06268'); // Just a demo showing how to generate the raw qbXML request print 'Here is the qbXML request we\'re about to send to QuickBooks Online Edition: ' . "\n"; print $Customer->asQBXML('CustomerAdd'); // Send the request to QuickBooks $API->addCustomer($Customer, '_add_customer_callback', 15); // This is our callback function, this will get called when the customer is added successfully function _add_customer_callback($method, $action, $ID, &$err, $qbxml, $Customer, $qbres) { print 'Customer #' . $ID . ' looks like this within QuickBooks Online Edition: ' . "\n"; print_r($Customer); } // Here's a demo of querying for customers with a specific name: $name = 'Keith Palmer Jr.'; // Here's how to fetch that customer by name $API->getCustomerByName($name, '_get_customer_callback', 15); function _get_customer_callback($method, $action, $ID, &$err, $qbxml, $Iterator, $qbres) { print 'This is customer #' . $ID . ' we fetched: ' . "\n"; print_r($Iterator); }