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) »
  • Implementation details of api v3 and helper functions
Pages: [1]

Author Topic: Implementation details of api v3 and helper functions  (Read 1250 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Implementation details of api v3 and helper functions
January 16, 2011, 04:23:11 am
Hi,

1) civicrm_create_success works only for _get
Eg. on civicrm_tag_create

Code: [Select]
    $tagBAO = CRM_Core_BAO_Tag::add($params, $ids);

    if ( is_a( $tagBAO, 'CRM_Core_Error' ) ) {
        return civicrm_create_error( "Tag is not created" );
    } else {
        $values = array( );
        _civicrm_object_to_array($tagBAO, $values);
        return civicrm_create_success($values);
    }

returns
{
   "is_error":0,
   "count":8,
   "values":{
      "id":6,
      "name":"toto",
                ...
}

should be

Code: [Select]
{
"is_error":0,
        "id":6,
"name":"toto",
}


Seems that as there is always a BAO/DAO that gets involved, we should get civicrm_return ($dao, "Error message if error")  that contains all the boilerplate code, no ?

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Implementation details of api v3 and helper functions
January 16, 2011, 11:01:14 am
I'm confused - I thought that what it is returning is as discussed / agreed between Erik & Lobo recently?
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: Implementation details of api v3 and helper functions
January 16, 2011, 02:34:56 pm
tag hasn't been v3ed yet

in v2, returns tag_id

was trying to use civicrm_return_success, but doesn't seem to work for create/delete, does it?

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Implementation details of api v3 and helper functions
January 16, 2011, 06:04:24 pm
OK - I thought you were referring to the bit where it is in a values array

   "values":{
      "id":6,
      "name":"toto",

per other conversations the id vs tag_id IS a problem but I think it will take a lot to work through all of it so we should hold off on focussing on it for now. (or we'll never get to step 7 and be able to enjoy that warm beer).

civicrm_contact_delete IS using create_success. Not sure I have a create example though
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: Implementation details of api v3 and helper functions
January 16, 2011, 11:40:41 pm
Got to check, but delete only returns is_error, create does return an id.

Quote from: Eileen on January 16, 2011, 06:04:24 pm

civicrm_contact_delete IS using create_success. Not sure I have a create example though
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Implementation details of api v3 and helper functions
January 16, 2011, 11:57:45 pm
Hmm - I suppose delete doesn't need to return an id because there isn't one anymore but it could return the id that was there... kind of hard to get excited either way - what's easiest?
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: Implementation details of api v3 and helper functions
January 17, 2011, 12:48:27 am
Doesn't matter much, but could be a nice touch to return it indeed.

My point was that civicrm_return_success expects to return a values = array(). That doesn't work for create/modify, that returns a single id, and we haven't discussed to my knowledge about what to return, but as soon as we agree on something, we can improve civicrm_return_success or another helper.
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: Implementation details of api v3 and helper functions
January 17, 2011, 01:14:57 am
As far as I go it we always will have an array as result of an API function in V3, so I would expect the create function to return an array containing a single element? That is what I have assumed in the civicrm_create_success in v3. If we decide otherwise, I need to change it to take care of single values.
So I would expect the result of the create to be array("id" => "2315") and therefore the civicrm_create_success to return:
is_error = 0
count = 1
values("id" => "2315");

I must confess I do not like the last bit, I would prefer to leave out the array in this case. But this is according to the standards agreed with Lobo?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Implementation details of api v3 and helper functions
January 17, 2011, 01:51:45 am
Quote from: Erik Hommel on January 17, 2011, 01:14:57 am
I must confess I do not like the last bit, I would prefer to leave out the array in this case. But this is according to the standards agreed with Lobo?

Agree, the v2 version seems nicer for me too.

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: Implementation details of api v3 and helper functions
January 17, 2011, 02:11:27 am
Then we will flatten it!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Implementation details of api v3 and helper functions
January 17, 2011, 01:53:26 pm
Just a note - I think create does return an array of values - which is probably a good thing - check the example in the examples folder
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Implementation details of api v3 and helper functions

This forum was archived on 2017-11-26.