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) »
  • Implement new API Call
Pages: [1]

Author Topic: Implement new API Call  (Read 616 times)

elcongrio

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 3.6.1
  • CMS version: Wordpress
  • MySQL version: 5.3
  • PHP version: 5.3.3
Implement new API Call
January 23, 2014, 12:11:00 pm
Hi:

I'm quite new as a CiviCRM developer, but quite experienced with Drupal and PHP.
I need to develop a new API feature, in order to retrieve County and State data stored at CiviCRM database. It's easy to do by direct query to the database, but I like to make it in a more civilized way, and if it can be a contribution to core code, much better.
Where can I start? There's some kind of "Extend the API for Dummies"?
Thanks

El Congrio

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Implement new API Call
January 23, 2014, 04:17:53 pm
Hi,

It would be great to add that in the core. The general principle is to add a api/v3/EntityName.php that contains the proper CRUD functions.

I got a deal for you: I give you the code, you write the unit test and do the PR.

Deal?

https://github.com/tttp/ep2014/blob/master/api/v3/Country.php

Your turn ;)

P.S. Minimally tested. Filters to retrieve only the active countries
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Implement new API Call
January 23, 2014, 05:29:57 pm
Xavier I don't think you should be using the deprecated "constant" api for this. Why didn't basic_get work?
@elcongrio if all you require is the list of countries and states then the api already exists.
Code: [Select]
// Fetch enabled countries
civicrm_api3('address', 'getoptions', array('field' => 'country_id'));
// Fetch all enabled states
civicrm_api3('address', 'getoptions', array('field' => 'state_province_id'));
// Fetch states for the US
civicrm_api3('address', 'getoptions', array('field' => 'state_province_id', 'country_id' => 'US'));
See http://wiki.civicrm.org/confluence/display/CRMDOC/Pseudoconstant+%28option+list%29+Reference
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Implement new API Call
January 23, 2014, 06:23:52 pm
you are right, I don't need it to work on 4.2 anymore. getoptions is the best way
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

elcongrio

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 3.6.1
  • CMS version: Wordpress
  • MySQL version: 5.3
  • PHP version: 5.3.3
Re: Implement new API Call
January 24, 2014, 05:00:55 am
Thank you very much Xavier. It's seems that the effort is best focused to another feature, but you got a deal!

@Coleman Watts, thanks for the tip. You just save me 3 days of work!!!


Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Implement new API Call
January 24, 2014, 10:59:20 am
No prob. Do refer to that reference sheet I linked for finer-grained options, including passing a context param that will show disabled options, or machine names, etc.
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) »
  • Implement new API Call

This forum was archived on 2017-11-26.