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) »
  • Customization of contact API for project
Pages: [1]

Author Topic: Customization of contact API for project  (Read 1040 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
Customization of contact API for project
May 27, 2010, 05:41:30 am
We are developing a link with an external application that will sync data with CiviCRM. We will use the standard API's as much as possible to enable this. For one part I need an API to access custom data, as we will keep the key of the other system in custom data.
So I have overridden the Contact API (meaning: made my own copy in my script folder) and added the following function:

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

/* params will hold the 'persoonsnummer_first' which is in the
   custom table civicrm_value_persoongegevens_2. Access this file
   first and then retrieve the contact_id from that table. This contact_id
   is then used to access the standard function civicrm_contact_get */

/* error if params does not hold pers_id_first */
if (!isset($params['pers_id_first'])) {
return civicrm_create_error( 'Persoonsnummer First niet aanwezig in
parameters' );
}

/* error if pers_id_first is empty */
if (empty($params['pers_id_first'])) {
return civicrm_create_error('Persoonsnummer First is leeg');
}

$pers_id_first = $params['pers_id_first'];

$query = "SELECT entity_id FROM civicrm_value_persoongegevens_2
WHERE persoonsnummer_first_9 = '$pers_id_first'";


$dao = & CRM_Core_DAO::executeQuery($query);
$i = 0;
while($dao->fetch()){
$contact_id = $dao->entity_id;
$i++;
}

$params = array('contact_id' => $contact_id);
return civicrm_contact_get($params, $deprecated_behavior = false);
}
« Last Edit: May 27, 2010, 10:16:56 am by Erik Hommel »
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: Customization of contact API for project
May 27, 2010, 12:35:59 pm
Should try the get api with custom_xxx=your id (and xxx being the id of your custom field), it should work

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: Customization of contact API for project
May 27, 2010, 12:45:11 pm
Thanx, Xavier, it does.....so I have the call:
Code: [Select]
$params = array('custom_9' => '345678');
$retrieved = &civicrm_contact_get( $params );

If I am correct this is not included in the documentation? If not, I will make a change to the wiki and flossmanual (if I am allowed).

Erik
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: Customization of contact API for project
May 27, 2010, 11:45:29 pm
Thanks to change the wiki.

As for the book, I feel that's too low level details of a specific implementation, Listing all the combinations of what parameters works for what api would be adding quite a few pages ;)

X+

P.S. To avoid maintenance problems, simply create a api/v2/XXX.php and put your custom apis there instead of hacking the common ones. Can be called with civicrm_XXX_ like the standard ones.
-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: Customization of contact API for project
May 28, 2010, 12:01:35 am
agreed for the book, will do the wiki today between meetings and shopping ... I had already made a copy of the API and made my change there, and left  the core API alone.
Erik
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) »
  • Customization of contact API for project

This forum was archived on 2017-11-26.