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) »
  • 3 REST API problems - could all be due to bootstrap issues?
Pages: [1]

Author Topic: 3 REST API problems - could all be due to bootstrap issues?  (Read 1321 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
3 REST API problems - could all be due to bootstrap issues?
February 10, 2012, 10:01:15 am
Hi,

I've seen 3 different problems when calling API functions over the REST interface (/sites/all/modules/civicrm/extern/rest.php) in 4.0:

(1) A custom API v3 function packaged into a module, as in http://civicrm.org/blogs/totten/extending-apiv3 "Put the new files in a Drupal module and add the module to the include path", works when called via /civicrm/ajax/rest but not when called externally via /sites/all/modules/civicrm/extern/rest.php . See http://forum.civicrm.org/index.php/topic,21685.msg93964.html#msg93964 (last tested in 4.0.6).

(2) The function drupal_get_path() is not always defined, when called in a custom API v3 function accessed via /sites/all/modules/civicrm/extern/rest.php . (In this case the custom API v3 function is defined under the custom PHP directory, due to problem (1)). Tested in 4.0.8.

(3) A civicrm_post hook is not consistently called following a contact + activities being created using civicrm_api('contact', 'create', ...) by the above custom API v3 function when accessed via /sites/all/modules/civicrm/extern/rest.php . The hook is called when the custom API v3 function is called via /civicrm/ajax/rest . Tested in 4.0.8.

We've worked around (1) by putting the function under the custom PHP dir, worked around (2) for now with a nasty hard-coded path and are contemplating working around (3) by taking the code out of a hook and calling it directly from the custom API function. Would be good to find a proper solution though, any ideas welcome.

Cheers,

Dave J

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: 3 REST API problems - could all be due to bootstrap issues?
February 10, 2012, 12:29:38 pm

can u check on why 2 happens

my initial guess was that the CMS was not bootstrapped, but then a quick check of the code shows it is bootstrapped

maybe because the config object is initialized before the script is bootstrapped? Can u check:

CRM/Utils/System/Drupal.php, search for CRM-6948

i suspect we might want to recreate the config object in a more general place. Not sure why rest defines its own loadBootstrap, seems bad coding to me :(

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

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: 3 REST API problems - could all be due to bootstrap issues?
February 13, 2012, 06:43:39 am
Hi Lobo,

Thanks for taking a look. I've tracked down (2) and (3): CRM_Utils_System::loadBootStrap() wasn't being called in CRM_Utils_REST::loadCMSBootstrap() because no UFMatch entry was found for the contact. Now working.

Thanks again,

Dave J

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • 3 REST API problems - could all be due to bootstrap issues?

This forum was archived on 2017-11-26.