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) »
  • New formats for API (experimental)
Pages: [1]

Author Topic: New formats for API (experimental)  (Read 675 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
New formats for API (experimental)
May 29, 2011, 04:44:14 pm
We have talked about making the api easier to use by having some alternative output formats handled through create_success. . I have had a go at implementing the formats as $params that I normally implement using wrappers. This is so you can do things like:


$params['format.true_false'] = 1;
if(civicrm_api('Contact','Create',$params) == 1 ){
   // it succeeded which is all I care about
}

The formats I tried all have examples in http://svn.civicrm.org/civicrm/branches/v3.4/api/v3/examples/Contact
'format.true_false'
'format.IDOnly'
'format.count'
'format.single_entity'
'format.single_value'


I also tried these formats in the context of chained / nested api calls (examples in the same location)

I wanted to build up an example of using CustomValue in chaining  so we could see how it looked being used alongside the other api :http://svn.civicrm.org/civicrm/branches/v3.4/api/v3/examples/Contact/APIChainedArrayMultipleCustom.php

NB I did have to edit my version of 'CustomValue' to accept 'entity_id' & 'entity_table' to work with nested calls - not checked in. In fact I have only checked in the examples at the moment.
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: New formats for API (experimental)
May 30, 2011, 03:06:47 am
I prefer
is_success to true_false
(and only_id to IDOnly, but cf below)

I like it, but it means that you got the BAO/DAO that retrieve everything and that you discard it for the end result, eg if you have format.count

It'd be much better to call the needed that does a select count() instead of selecting everything and discarding the values. I have no idea if it's possible

I think it's better to create new apis getCount, getOne/getSingle, getField instead of having them as options of the get action.

(benefit beside being "clearer" is that you can use your generic code for now, and override for some entities, eg civicrm_api3_contact_getCount that would use the existing count functions directly.

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: New formats for API (experimental)
May 30, 2011, 08:21:37 am
I agree with Xavier that doing a select count instead of invoking the BAO/DAO when it is not necessary. And I also like is_success better than true_false ;D
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • New formats for API (experimental)

This forum was archived on 2017-11-26.