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) »
  • API - pass in custom field as criteria
Pages: [1]

Author Topic: API - pass in custom field as criteria  (Read 2995 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
API - pass in custom field as criteria
August 11, 2009, 05:09:41 am
Hi there,

Is it possible to pass in a custom field as a criteria for the contact_get api. I have been playing with the example in Xavier's blog and had some success but I'm not sure if I can pass in a custom field - and if so what the format is. Using a whole swag of smart groups isn't practical for one of the scenarios I am looking at.

{crmAPI entity='contact' action="search" var="contacts" rowCount="10" contact_type="Individual" custom_15="1" group="26" json="1" return ="sort_name, custom_15, group"}
<ul>
{foreach from=$contacts item=contact}
<li id="contact_{$contact.contact_id}">{$contact.sort_name}</li>
<li id="group">{$contact.custom_15}</li>

{/foreach}
</ul>

NB - I do get this error on my 3.0 test site with the above code -even if I take out the references to custom_15 and the rather optimistic reference to json="1" ( I was hopeful I might be able to get it back in that format if I passed that in)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: API - pass in custom field as criteria
August 11, 2009, 06:54:46 am
there was minor bug, which is fixed in r23239

might want to take a look for patch : http://fisheye.civicrm.org/changelog/CiviCRM?cs=23239

kiran
You Are Designed To Choose... Defined By Choice.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API - pass in custom field as criteria
August 11, 2009, 12:37:35 pm
So, that's the answer to the 'NB'? But is there an answer to the original question?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API - pass in custom field as criteria
August 11, 2009, 01:27:09 pm

you might want to do this as a php code snippet  and get it to work. all custom fields that are marked searchable can be used in contact_get / contact_search

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API - pass in custom field as criteria
August 11, 2009, 01:40:56 pm
OK - you mean post on the wiki?  - Am I correct about the format::

custom_15
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API - pass in custom field as criteria
August 11, 2009, 01:43:10 pm

no i meant, write a small php script and get it to work first using the api, and then try to migrate it to using the template call.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API - pass in custom field as criteria
August 11, 2009, 01:44:50 pm
I've mostly been testing them using the url method - i.e. the rest call but can try that
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API - pass in custom field as criteria
August 15, 2009, 03:02:37 am
Actually - my syntax was correct BUT when I checked to make sure the field was searchable I found I was using the group number not the field number. (ie. custom_15 should have been custom_69).

Anyway, great to realise this API allows searching by searchable fields and groups.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API - pass in custom field as criteria
August 21, 2009, 05:35:06 pm
and tag, and...

As you're realised, that's a dumb wrapper around the api, whatever feature the api provides, crmAPI provides too.

I personally find easier to test using the REST wrapper:

http://example.org/civicrm/ajax/rest?fnName=civicrm/contact/search&group=2&contact_type=Individual&return[sort_name]=1&group=7&custom_42=douglas&rowCount=200&country=1134

See what I get that way
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API - pass in custom field as criteria

This forum was archived on 2017-11-26.