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) »
  • Contact API, which function is correct to add contact
Pages: [1]

Author Topic: Contact API, which function is correct to add contact  (Read 799 times)

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
Contact API, which function is correct to add contact
August 16, 2010, 01:43:14 am
According to the documentation page, the function civicrm_contact_add should be used to add a contact. In the source of the API however, civicrm_contact_create is used. Is it not better to update the documentation and point new users to civicrm_contact_create? If so, I will change the documentation.
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

chirayu

  • Guest
Re: Contact API, which function is correct to add contact
August 23, 2010, 03:18:08 am
So Erik should we use cicicrm_contact_add or civicrm_contact_create to add contacts?

I am already using civicrm_contact_add and it seems to work fine.

Chirayu

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: Contact API, which function is correct to add contact
August 23, 2010, 03:22:58 am
The civicrm_contact_add works fine, that is not the issue. But if you look in the code, all the civicrm_contact_add does is call the civicrm_contact_create:

Code: [Select]
function &civicrm_contact_add( &$params ) {
    _civicrm_initialize( );

    $contactID = CRM_Utils_Array::value( 'contact_id', $params );

    if ( !empty($contactID) ) {
        $result = civicrm_contact_update($params);
    } else {
        $result = civicrm_contact_create($params);
    }
    return $result;
}

This is according to the new standards for API (see this post: http://forum.civicrm.org/index.php/topic,15252.0.html). If we use the new standars, we should use the civicrm_contact_create. Even if the civicrm_contact_add still works (and should remain working so as to not force users to rewrite their code).
My point is that we need to update the documentation to advise the civicrm_contact_create (which I will do right now :-))
Erik
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: Contact API, which function is correct to add contact
August 24, 2010, 04:28:05 pm
yay Erik!
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) »
  • Contact API, which function is correct to add contact

This forum was archived on 2017-11-26.