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) »
  • Custom API & Populating API Explorer Select List
Pages: [1]

Author Topic: Custom API & Populating API Explorer Select List  (Read 466 times)

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Custom API & Populating API Explorer Select List
March 11, 2015, 08:47:10 am
How can I customize my API to work with the API explorer so that I have a drop-down box to select parameters, and related values, etc? I find this super convenient when I'm trying to test something on the fly and can't recall the exact param name.

Thanks!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom API & Populating API Explorer Select List
March 11, 2015, 12:52:44 pm
What are you adding? it should be fairly dynamic and adjust the list (for entities, probably not for actions?)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Custom API & Populating API Explorer Select List
March 11, 2015, 02:23:23 pm
I'm creating my own API calls. I have noticed that for some of the built in API functions you can select parameters from a drop-down list. None of my API for my extension do that... I have to select "other" and then manually type the parameter.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Custom API & Populating API Explorer Select List
March 11, 2015, 06:12:56 pm
The "magic" that populates the param lists is getfields. For "standard" actions like "get" and "create" getfields gets these from the schema, although individual apis can adjust them by declaring a _api3_entity_action_spec() function. For random other actions you make up, implement a the same function and just declare all of the fields. Here's an example of doing so:
https://github.com/civicrm/civicrm-core/blob/4.6/api/v3/MessageTemplate.php#L135

Note that 2 more piece of magic were added in 4.6 which is to show the "description" for your field, and to show fields even if they do not declare a "name" property. Declaring a "name" property is totally redundant because it's always the same as the array key (note that the example and most apis don't bother to do it), but it caused them to get overlooked in the API explorer if they were missing... that's now fixed in 4.6.
Try asking your question on the new CiviCRM help site.

lee.gooding

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
    • Clear River Church
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.7
  • PHP version: 5.3
Re: Custom API & Populating API Explorer Select List
March 12, 2015, 10:32:38 am
Awesome. I'll mess with this soon. Hopefully I can get it implemented and then add some documentation to the wiki.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Custom API & Populating API Explorer Select List
March 12, 2015, 10:50:14 am
BTW Xavier in the new API explorer all lists are dynamic, including actions :)
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Custom API & Populating API Explorer Select List

This forum was archived on 2017-11-26.