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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Error when using OO API
Pages: [1]

Author Topic: Error when using OO API  (Read 539 times)

kenahoo

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.3.16
Error when using OO API
January 07, 2014, 05:55:53 am
I'm trying to use the OO API to search for contacts, but something seems wrong in my setup.

In a module I have this:

Code: [Select]
require_once 'sites/all/modules/civicrm/api/class.api.php';

And in a node I have this:

Code: [Select]
$api = new civicrm_api3();
$params = array(
  'sequential' => 1,
  'contact_type' => 'Individual'
);
$result = $api->Contact->Get($params);

That results in the following error in the Apache log:

Code: [Select]
[Mon Jan 06 22:53:01 2014] [error] [client ::1] PHP Fatal error:  Class 'CRM_Core_Config' not found in
/Users/ken/Documents/SIA/site-upgrade/sites/all/modules/civicrm/api/class.api.php on line 122, referer:
http://localhost/node/5/edit

Any ideas?

I'm running Drupal 7.24, CiviCRM 4.4, and PHP 5.3.26.

Thanks.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Error when using OO API
January 07, 2014, 10:21:18 am
I think first you have to call
Code: [Select]
civicrm_initialize();
Try asking your question on the new CiviCRM help site.

kenahoo

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.3.16
Re: Error when using OO API
January 07, 2014, 07:14:06 pm
That doesn't seem to help - if I add that right after loading the API:

Code: [Select]
require_once 'sites/all/modules/civicrm/api/class.api.php';
civicrm_initialize( );

then it doesn't seem to know about the function:

Code: [Select]
[Tue Jan 07 20:53:54 2014] [error] [client ::1] PHP Fatal error:  Call to undefined function civicrm_initialize() in /Users/ken/Documents/SIA/site-upgrade/sites/all/modules/SIA_custom/SIA_custom.module on line 4, referer: http://localhost/node/5/edit

I see that civicrm_initialize() is defined in sites/all/modules/civicrm/drupal/civicrm.module, but I don't know why that's not loaded.  I do have CiviCRM 4.4 installed and enabled, and even listed as a prerequisite of my module.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Error when using OO API
January 07, 2014, 07:26:55 pm
I think you should call civicrm_initialize() first.
Try asking your question on the new CiviCRM help site.

kenahoo

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.3.16
Re: Error when using OO API
January 07, 2014, 08:20:04 pm
Doesn't help, it's still undefined if I move it one line earlier.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Error when using OO API
January 09, 2014, 02:27:06 am
Weird, I thought these problems were solved, hadn't seen them forever. Did you change something on the weight of the modules? civicrm should already be loaded before your module, isn't it?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

kenahoo

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.3.16
Re: Error when using OO API
January 09, 2014, 05:43:35 am
I didn't change anything in the module weights (didn't even know you could until now!), but I think that may be the problem:

Code: [Select]
mysql> select name, type, status, weight from system where name like 'SIA%' or name like 'civ%' order by weight;
+--------------------------+--------+--------+--------+
| name                     | type   | status | weight |
+--------------------------+--------+--------+--------+
| siabp2                   | theme  |      1 |      0 |
| SIA_custom               | module |      1 |      0 |
| civicrmtheme             | module |      0 |      0 |
| civicrm_constant_contact | module |      0 |      0 |
| civicrm_engage           | module |      0 |      0 |
| civicrm_og_sync          | module |      0 |      0 |
| civicrm_contact_ref      | module |      0 |      0 |
| civicrm_member_roles     | module |      0 |      0 |
| civicrm                  | module |      1 |    100 |
| civicrm_rules            | module |      0 |    110 |
| civicrm_group_roles      | module |      0 |    110 |
+--------------------------+--------+--------+--------+

Is the weight supposed to be set automatically by looking at the dependencies?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Error when using OO API

This forum was archived on 2017-11-26.