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) »
  • Issue getting API functions to work (Resolved)
Pages: [1]

Author Topic: Issue getting API functions to work (Resolved)  (Read 1812 times)

kengle3

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
Issue getting API functions to work (Resolved)
July 18, 2009, 06:44:46 am
Hello,

I'm trying to get the API functions to work under drupal by following the example in the documentation found here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets

The example they give is below:
Code: [Select]
civicrm_initialize( );
require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );
require_once "api/v2/Contribute.php";
$contribution = civicrm_contribution_get(); now make API call // do whatever you want with your contribution

The documentation states to also include civicrm.settings.php, $civicrm_root/CRM/Core/Config.php, and at least for the example's case api/v2/Contribute.php.

After adding these includes at the top of the php file, attempting to run the example causes "Call to undefined function civicrm_initialize()"

Am I missing another include?
« Last Edit: August 05, 2009, 10:42:09 pm by kengle3 »

abrookins

  • I’m new here
  • *
  • Posts: 21
  • Karma: 5
    • Redspire (Blog)
Re: Issue getting API functions to work
July 19, 2009, 10:35:08 am
If the CiviCRM module is installed properly and enabled, calling civicrm_initialize() within code loaded by Drupal should work.

You can test if Drupal sees the CiviCRM module with the module_exists function (http://api.drupal.org/api/function/module_exists):

Code: [Select]
if (module_exists('civicrm')) {
    // do some test like:
    drupal_set_message('CiviCRM exists!');
}

Seeing your code rather than the example code would help us identify the problem. 

Also, are you writing a Drupal module with this code appearing in the .module or .inc files, or is this a file you are including from within (or directly inserted into) the body of a node?

Best,
Andrew

kengle3

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
Re: Issue getting API functions to work
August 05, 2009, 10:41:49 pm
I got it working now. i was writing it in a Drupal module .module file, and I believe the issue was that I wasn't writing it in the CiviCRM context.

Thanks for your response =)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Issue getting API functions to work (Resolved)

This forum was archived on 2017-11-26.