I am using Consolibyte's PHP/QB integration to insert/update customers to QB on a local machine.
When I initially run the PHP script to insert information from mysql DB to QB, everything went through--GREAT.
However, when I added a new customer into the mysql DB and ran the consolibyte script again, I received the following error:
Description: Error message received from application via getLastError(): 3100: The name "John Smith" of the list element is already in use.
I know that I can't insert a duplicate name, but is there a way I can tell the script to skip names that are already in the QB database, instead of aborting the script due to a duplication error?
According to the documentation, I can pass a unique identifier into QB and make it unique, but my objective is to skip this process as a whole
http://www.consolibyte.com/wiki/doku.php/quickbooks_error_codes
FUNCTION.PHP
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
/*
<CustomerRef>
<ListID>80003579-1231522938</ListID>
</CustomerRef>
*/
$customer = mysql_fetch_assoc(mysql_query("SELECT * FROM qb_cust_test WHERE cust_id = " . (int) $ID));
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>'.$customer['f_name'].' '.$customer['l_name'].'</Name>
<FirstName>'.$customer['f_name'].'</FirstName>
<LastName>'.$customer['l_name'].'</LastName>
<Phone>'.$customer['phone'].'</Phone>
<Email>'.$customer['email'].'</Email>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
/**
* Receive a response from QuickBooks
*/
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
mysql_query("
UPDATE
qb_cust_test
SET
quickbooks_listid = '" . mysql_real_escape_string($idents['ListID']) . "',
quickbooks_editsequence = '" . mysql_real_escape_string($idents['EditSequence']) . "'
WHERE
id = " . (int) $ID);
}
//continue if error is 3100
$errmap = array(
'*' => 'catch_all_errors'
);
function catch_all_errors($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
if ($action == QUICKBOOKS_ADD_CUSTOMER and $errnum == 3100)
{
return true; // Ignore this error, all is OK - customer already exists
}
// Some other error occurred, stop processing
return false;
}
ADD_CUSTOMER.php
<?php
/**
* Require some configuration stuff
*/
require_once dirname(__FILE__) . '/config.php';
// Queue up the customer add
// Select all customers first
$customers = mysql_query("SELECT * FROM qb_cust_test");
while($customer = mysql_fetch_assoc($customers)) {
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $customer['cust_id']);
}
die('Customer submitted!');