Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getContacts does not seem to be respecting searchTerm #311

Open
thepilot21 opened this issue Feb 9, 2023 · 5 comments
Open

getContacts does not seem to be respecting searchTerm #311

thepilot21 opened this issue Feb 9, 2023 · 5 comments
Assignees

Comments

@thepilot21
Copy link

I am using the getContacts example code from the SDK. My $searchTerm text = "Tracey" but all Contacts (only have 3 at the moment) are being returned in $result rather than just the matching one that I want. Here is my test code section.

$ifModifiedSince = new DateTime("2020-02-06T12:17:43.202-08:00");
$where = 'ContactStatus=="' . XeroAPI\XeroPHP\Models\Accounting\Contact::CONTACT_STATUS_ACTIVE . '"';
echo $where;
$order = "Name ASC";
$iDs = array("00000000-0000-0000-0000-000000000000");
$page = 0;
$includeArchived = true;
$summaryOnly = true;
$searchTerm = "Tracey";

try {
  $result = $apiInstance->getContacts($xeroTenantId, $ifModifiedSince, $where, $order,null, $page, $includeArchived, $summaryOnly, $searchTerm);
} catch (Exception $e) {
  echo 'Exception when calling AccountingApi->getContacts: ', $e->getMessage(), PHP_EOL;
}
echo '<pre>' . var_export($result, true) . '</pre>';

Many thanks for any assistance.

Mike
PS. The example code in the docs has a syntax error on the $where line which I have corrected in my code.

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

PETOSS-268

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

Thanks for raising an issue, a ticket has been created to track your request

@pumpkinball
Copy link
Contributor

Hi Mike,
Thanks for this. When I tried this in my test system it worked correctly.
Here's what I have:-
// read all contacts $result = $apiInstance->getContacts($xeroTenantId); // filter by contacts by status $where = 'ContactStatus=="ACTIVE"'; $order = "Name ASC"; $page = 0; $includeArchived = true; $summaryOnly = true; $searchTerm = "Sandra"; $result2 = $apiInstance->getContacts($xeroTenantId, null, $where, $order,null,$page,$includeArchived,$summaryOnly,$searchTerm);

It may be worth trying it firstly with includeArchived set to false, in case you have a large amount of archived contacts (called Tracey!) and secondly try running it via API Explorer, which is a great way to simulate code.

@pumpkinball pumpkinball self-assigned this Feb 9, 2023
@thepilot21
Copy link
Author

Thanks for looking at this so quickly pumpkinball. I tried your exact code but I still got 3 records returned (the only 3 contacts setup so far) and I would have expected no records would be returned since I don't have a Contact called Sandra

So my code now looks like this:-

  $config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( (string)$storage->getSession()['token'] );
  $apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
      new GuzzleHttp\Client(),
      $config
  );

// read all contacts $result = $apiInstance->getContacts($xeroTenantId); // filter by contacts by status
 $where = 'ContactStatus=="ACTIVE"'; $order = "Name ASC"; $page = 0; $includeArchived = false; $summaryOnly = true; $searchTerm = "Sandra"; 
 $result2 = $apiInstance->getContacts($xeroTenantId, null, $where,$order,null,$page,$includeArchived,$summaryOnly,$searchTerm); 

echo '<pre>' . var_export($result2, true) . '</pre>';

and the var_export lists 3 contacts as follows (some redacting of email etc with XXXXXXX)

`XeroAPI\XeroPHP\Models\Accounting\Contacts::__set_state(array(
   'container' => 
  array (
    'contacts' => 
    array (
      0 => 
      XeroAPI\XeroPHP\Models\Accounting\Contact::__set_state(array(
         'container' => 
        array (
          'contact_id' => '6a4e8134-83bb-42cc-9ae0-13da5cf94b7f',
          'contact_number' => NULL,
          'account_number' => '333',
          'contact_status' => 'ACTIVE',
          'name' => 'dBXXX',
          'first_name' => 'Mike',
          'last_name' => 'WXXX',
          'email_address' => '[email protected]',
          'skype_user_name' => NULL,
          'contact_persons' => NULL,
          'bank_account_details' => NULL,
          'tax_number' => NULL,
          'accounts_receivable_tax_type' => NULL,
          'accounts_payable_tax_type' => NULL,
          'addresses' => NULL,
          'phones' => 
          array (
          ),
          'is_supplier' => NULL,
          'is_customer' => NULL,
          'default_currency' => NULL,
          'xero_network_key' => NULL,
          'sales_default_account_code' => NULL,
          'purchases_default_account_code' => NULL,
          'sales_tracking_categories' => NULL,
          'purchases_tracking_categories' => NULL,
          'tracking_category_name' => NULL,
          'tracking_category_option' => NULL,
          'payment_terms' => NULL,
          'updated_date_utc' => '/Date(1675936332493+0000)/',
          'contact_groups' => NULL,
          'website' => NULL,
          'branding_theme' => NULL,
          'batch_payments' => NULL,
          'discount' => NULL,
          'balances' => NULL,
          'attachments' => NULL,
          'has_attachments' => false,
          'validation_errors' => NULL,
          'has_validation_errors' => false,
          'status_attribute_string' => NULL,
        ),
      )),
      1 => 
      XeroAPI\XeroPHP\Models\Accounting\Contact::__set_state(array(
         'container' => 
        array (
          'contact_id' => '5a5b62e7-c18b-4eee-a5b4-e2868b8f3993',
          'contact_number' => NULL,
          'account_number' => NULL,
          'contact_status' => 'ACTIVE',
          'name' => 'FooBar',
          'first_name' => 'Foo',
          'last_name' => 'Bar',
          'email_address' => '[email protected]',
          'skype_user_name' => NULL,
          'contact_persons' => NULL,
          'bank_account_details' => '',
          'tax_number' => NULL,
          'accounts_receivable_tax_type' => NULL,
          'accounts_payable_tax_type' => NULL,
          'addresses' => NULL,
          'phones' => 
          array (
          ),
          'is_supplier' => NULL,
          'is_customer' => NULL,
          'default_currency' => NULL,
          'xero_network_key' => NULL,
          'sales_default_account_code' => NULL,
          'purchases_default_account_code' => NULL,
          'sales_tracking_categories' => NULL,
          'purchases_tracking_categories' => NULL,
          'tracking_category_name' => NULL,
          'tracking_category_option' => NULL,
          'payment_terms' => NULL,
          'updated_date_utc' => '/Date(1675178591443+0000)/',
          'contact_groups' => NULL,
          'website' => NULL,
          'branding_theme' => NULL,
          'batch_payments' => NULL,
          'discount' => NULL,
          'balances' => NULL,
          'attachments' => NULL,
          'has_attachments' => false,
          'validation_errors' => NULL,
          'has_validation_errors' => false,
          'status_attribute_string' => NULL,
        ),
      )),
      2 => 
      XeroAPI\XeroPHP\Models\Accounting\Contact::__set_state(array(
         'container' => 
        array (
          'contact_id' => '[84364488-62](glocom://8436448862)ca-41f6-93c9-a901c64acccb',
          'contact_number' => NULL,
          'account_number' => NULL,
          'contact_status' => 'ACTIVE',
          'name' => 'Tracey',
          'first_name' => NULL,
          'last_name' => NULL,
          'email_address' => '',
          'skype_user_name' => NULL,
          'contact_persons' => NULL,
          'bank_account_details' => '',
          'tax_number' => NULL,
          'accounts_receivable_tax_type' => NULL,
          'accounts_payable_tax_type' => NULL,
          'addresses' => NULL,
          'phones' => 
          array (
          ),
          'is_supplier' => NULL,
          'is_customer' => NULL,
          'default_currency' => 'GBP',
          'xero_network_key' => NULL,
          'sales_default_account_code' => NULL,
          'purchases_default_account_code' => NULL,
          'sales_tracking_categories' => NULL,
          'purchases_tracking_categories' => NULL,
          'tracking_category_name' => NULL,
          'tracking_category_option' => NULL,
          'payment_terms' => NULL,
          'updated_date_utc' => '/Date(1675197083667+0000)/',
          'contact_groups' => NULL,
          'website' => NULL,
          'branding_theme' => NULL,
          'batch_payments' => NULL,
          'discount' => NULL,
          'balances' => NULL,
          'attachments' => NULL,
          'has_attachments' => false,
          'validation_errors' => NULL,
          'has_validation_errors' => false,
          'status_attribute_string' => NULL,
        ),
      )),
    ),
  ),
))`

Much appreciate any thoughts on why this appears to work for you but not for me :-)

By the way I did try searching the Name field explicitly using the $where and that works OK so I could probably work around this issue.

Mike

@pumpkinball
Copy link
Contributor

Hi @thepilot21 it does seem bizarre that it's not working for you.
Can you try it by entering in those parameters manually via API Explorer? What happens there? And can you try it for a different organisation (tenant), and see what happens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants