CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • AJAX API Search by "AND"-ing two Tags
Pages: [1]

Author Topic: AJAX API Search by "AND"-ing two Tags  (Read 330 times)

bstalcup

  • I post occasionally
  • **
  • Posts: 47
  • Karma: 1
  • CiviCRM version: 4.7.3
  • CMS version: Joomla!
  • MySQL version: 5.5.36-cll-lve
  • PHP version: 5.3.29
AJAX API Search by "AND"-ing two Tags
March 04, 2016, 08:12:50 am
Note: I asked this question on the Stack Exchange (http://civicrm.stackexchange.com/questions/10166/civi-ajax-api-search-by-anding-2-tags) But came up empty.

I would like to search the Civi API for Contacts that have both of two tags. I'm at a loss as to how to do this. Right now if you provide multiple tags, the default is to use an OR operation. For example:

Code: [Select]
CRM.api3('Contact', 'get', {
  "sequential": 1,
  "tag": [5,7]
  "return": ["tag","first_name"]
}).done(function(result) {
  // do something
});

Returns all of the contacts that have either tag with ID=5 OR tag with ID=7. I have also tried using the IN and BETWEEN operations, to no avail.  This piece of functionality is pretty crucial to the tool I'm building, because the workaround I can think of is to fetch all the (several thousand) contacts who have both tags, get them on client side, and parse through it to find all who have both tags.  This is super computationally-intensive on both the server side (large SQL query + constructing huge JSON) and the client side (parsing through a several-thousand element array).  Any leads as to how to work around this, or how to get this functionality working would very much help me out. 

Thank you!
« Last Edit: March 04, 2016, 08:35:27 am by bstalcup »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • AJAX API Search by "AND"-ing two Tags

This forum was archived on 2017-11-26.