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 (Moderator: Donald Lobo) »
  • CiviCRM API call from drupal block is throwing error
Pages: [1]

Author Topic: CiviCRM API call from drupal block is throwing error  (Read 1973 times)

luismiguel2001us

  • Guest
CiviCRM API call from drupal block is throwing error
August 15, 2009, 02:29:58 pm
Hi folks,

I have tried to create a page in Drupal where I pull some information from civi. Once I created a new drupal page (node) I switched to PHP processing and wrote the following code:

<?php

   global $user;
   $myID = $user->uid;

   if ( module_exists('civicrm') ) {
      civicrm_initialize( );

      // Initialization call is required to use CiviCRM APIs.
      civicrm_initialize( );

      $ufMatchId =  civicrm_uf_match_id_get($myID);
      print( $ufMatchId );
   }

?>

Unfortunately I am getting code undefined error.
Fatal error: Call to undefined function civicrm_uf_match_id_get() in /home/donordep/public_html/includes/common.inc(1537) : eval()'d code on line 12


I am new to the Civi API and I have not been able to make this work. If someone can help me out I would really appreciate it.

Luis

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM API call from drupal block is throwing error
August 15, 2009, 03:42:06 pm

you need

Code: [Select]
require_once 'api/v2/UFMatch.php';

before the all to civicrm_uf_match_id_get

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

luismiguel2001us

  • Guest
Re: CiviCRM API call from drupal block is throwing error
August 16, 2009, 05:21:50 am
Hi lobo,

Thanks for your answer. Unfortunately that did not work either, since the file UFMatch.php does not exist in api/v2. So Drupal throws the following error.

Fatal error: require_once() [function.require]: Failed opening required 'api/V2/UFMatch.php' (include_path='.:/usr/lib/php') in /home/public_html/includes/common.inc(1537) : eval()'d code on line 2

If found the file UFMatch.php in two locations

/public_html/sites/all/modules/civicrm/CRM/Core/DAO/UFMatch.php
/public_html/sites/all/modules/civicrm/CRM/Core/BAO/UFMatch.php

and tried to use either one in the required command line. However that did not work either. I am using Civicrm 2.2.7, but is there something else that I need to download to make this work? Thanks for your help.

Luis

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM API call from drupal block is throwing error
August 16, 2009, 05:41:05 am

argh

the file is: api/v2/UFGroup.php

sorry about the typo :(

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

luismiguel2001us

  • Guest
Re: CiviCRM API call from drupal block is throwing error
August 16, 2009, 06:17:37 am
Hi lobo,

Thanks for your help. I got this to work now. Here is the final code that is working for me. This may be useful to others in the future.

<?php
if ( module_exists('civicrm') ) {
   require_once ('/home/public_html/sites/all/civicrm.settings.php');
   require_once ($civicrm_root . '/CRM/Core/Config.php');
   $config =& CRM_Core_Config::singleton( );

   require_once 'api/v2/UFGroup.php';

   global $user;
   $myID = $user->uid;

   // Initialization call is required to use CiviCRM APIs.
   civicrm_initialize( );

   $ufMatchId =  civicrm_uf_match_id_get($myID);
   print( $ufMatchId );
}
?>


This is the URL that had some information on this issue.

http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets#UsingCiviCRMAPIs-CodeSnippets-DisplayasortedlistofgroupmembersinaDrupalblockusingcivicrmcontactsearch

Thanks,
Luis

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviCRM API call from drupal block is throwing error

This forum was archived on 2017-11-26.