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) »
  • unable to use civicrm api v3 in custom module
Pages: [1]

Author Topic: unable to use civicrm api v3 in custom module  (Read 521 times)

shashikant

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
  • CiviCRM version: civicrm 4.1.3
  • CMS version: Drupal 6.26
  • MySQL version: Mysql 5.1.56
  • PHP version: PHP Version 5.3.6
unable to use civicrm api v3 in custom module
February 07, 2013, 05:58:04 am
Hi
I am trying to use civicrm api v3 in my custom module.
I am using civicrm 4.1.2 and drupal 6.25
I am following this doc
http://book.civicrm.org/developer/version/4.1/techniques/api

The  document says
Quote
The recommended way to call the API in PHP is

require_once 'api/api.php';
$result = civicrm_api ($entity,$action,$params);

but when i add "require_once 'api/api.php';" it gives me
Code: [Select]
PHP Fatal error:  require_once()  Failed opening required 'api/api.php'
I also tried by adding civicrm_initialize( ); in code, and when i do so

i get 
Code: [Select]
PHP Fatal error:  Call to undefined function civicrm_initialize()
how can i use civicrm api v3 in module?

Thanks.

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: unable to use civicrm api v3 in custom module
February 07, 2013, 09:01:14 am
Sounds like CiviCRM is not yet initialized....
try this first?

Code: [Select]
require_once($_SERVER['DOCUMENT_ROOT'].'/your folder/sites/default/civicrm.settings.php');

require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

shashikant

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
  • CiviCRM version: civicrm 4.1.3
  • CMS version: Drupal 6.26
  • MySQL version: Mysql 5.1.56
  • PHP version: PHP Version 5.3.6
Re: unable to use civicrm api v3 in custom module
February 18, 2013, 05:37:50 am
Hi Erik,
Sorry for late reply.
I was doing wrong.
I had written the require_once 'api/api.php'; at the staring of the file and i was using civicrm api under function.
When I included the statement require_once 'api/api.php'; under the function where i am using civicrm api.
Then it got working.

Regards
Shashikant

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: unable to use civicrm api v3 in custom module
February 18, 2013, 08:02:00 am
That makes sense Shashikant, glad it works now :-)
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) »
  • unable to use civicrm api v3 in custom module

This forum was archived on 2017-11-26.