Is it possible to do a membership get api request with a "LIKE" operator with wildcards for membership_type_id? Trying this out, I get

CiviCRM_API3_Exception: [2001: 'Something%' is not a valid option for field membership_type_id

Which is fair enough enough but it means that LIKE isn't supported even though it's in the api explorer's operator dropdown.



SQL doesn't support LIKE for integer fields. For something like membership type id I'm not even sure what it would mean unless you have 10 or more, and even then still not really meaningful.

  • membership_type_id actually supports using the membership type name as well. Try the API explorer to see how it works. – sdragnev Jul 20 '16 at 23:08
  • I saw there was another field membership_type. IDs are integers so it's kind of weird if an id query matches on a name/string. I'd expect to query on membership_type if I wanted string match. – Demerit Jul 21 '16 at 3:05
  • That's a fairly new development for convenience's sake, but yeah, it's a little confusing. It applies for other similar fields as well, eg option_group_id. – sdragnev Oct 2 '16 at 19:38

Please use the following -

For any integer you can use IN rather than Like

$result = civicrm_api3('Membership', 'get', array(
  'sequential' => 1,
  'membership_type_id' => array('IN' => array("General", "Student")),

If selecting string LIKE is used

$result = civicrm_api3('Membership', 'get', array(
  'sequential' => 1,
  'source' => array('LIKE' => "payment"),

I guess this helps!!!


It seems it is working now in 2018 (have tried to find Relationships Type). Just put a search term (a word or part of something) in"LIKE" text area as %YourSearchTerm%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.