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) »
  • Contact custom data not returning, but works in API explorer
Pages: [1]

Author Topic: Contact custom data not returning, but works in API explorer  (Read 358 times)

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Contact custom data not returning, but works in API explorer
December 02, 2014, 04:33:38 am
I've found that one of our unit tests (a test we've actually had for a while) is failing because an API call it does is not returning the requested custom data. It works from the API explorer, and the information shows in civicrm/contact/view, but when the example code is pasted it doesn't return the custom field. It also doesn't return the custom field when I put the same params into drush cvapi.

API explorer call:
Code: [Select]
/civicrm/ajax/rest?entity=Contact&action=getsingle&debug=1&sequential=1&json=1&contact_type=Individual&contact_sub_type=Student&return=custom_32&contact_id=90948
Sample code from that:
Code: [Select]
$params = array(
  'version' => 3,
  'sequential' => 1,
  'contact_type' => 'Individual',
  'contact_sub_type' => 'Student',
  'return' => 'custom_32',
  'contact_id' => 90948,
);
$result = civicrm_api('Contact', 'getsingle', $params);

drush cvapi:
Code: [Select]
drush cvapi Contact.getsingle sequential=1 contact_type=Individual contact_sub_type=Student return=custom_32 contact_id=90948
getvalue is the same, it returns the custom value in the API explorer but not in code or drush. The relevant CustomValue.get call works in all three of these places.

We've had similar issues with Activity custom fields, but that was fixed by passing the activity_type_id. I'm already passing the contact type and subtype the custom field applies to, and it's the same with or without.

Can you see anything wrong with the code above? Is this something known not to work in 4.4.6?

Thanks,
David
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Contact custom data not returning, but works in API explorer
December 02, 2014, 05:18:26 am
I might (or might not) be linked with some weird side effect because drush doesn't have a user by default and civi mostly doesn't care, unless it does. Try to add the user (-u 1) see how it goes.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Contact custom data not returning, but works in API explorer
December 02, 2014, 07:28:27 am
That worked on the command line. I had to change part of the bootstrap for our unit tests and in my standalone API call testing script to get it working there- it was supposed to be logging in uid 1 but obviously wasn't doing it properly.
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Contact custom data not returning, but works in API explorer

This forum was archived on 2017-11-26.