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) »
  • API not returning custom data
Pages: [1]

Author Topic: API not returning custom data  (Read 5024 times)

Jacob Hilton

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.2.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.30-30.2
  • PHP version: 5.2.17
API not returning custom data
August 01, 2013, 02:50:38 am
I wrote a PHP script using the API that spontaneously stopped working a couple of weeks ago.  When I isolated the problem I found that the API was not returning custom data fields in the way I expected.

For example, I have Age stored in custom_261. The following works correctly: mysite/ajax/rest?json=1&sequential=1&debug=1&entity=Contact&action=get&custom_261=22&return=country&rowCount=1 returns:

{
   "is_error":0,
   "version":3,
   "count":1,
   "id":7857,
   "values":[{
      "contact_id":"7857",
      "contact_is_deleted":"0",
      "address_id":null,
      "country_id":null,
      "country":null,
      "civicrm_value_survey__80k_36_id":"44",
      "custom_261":"22",
      "id":"7857"
   }]
}

As you can see, data for both country and custom_261 are returned, as expected.

However, the following does not seem to work correctly: mysite/ajax/rest?json=1&sequential=1&debug=1&entity=Contact&action=get&return=custom_261&rowCount=1 returns:

{
   "is_error":0,
   "version":3,
   "count":1,
   "id":1,
   "values":[{
      "contact_id":"1",
      "contact_is_deleted":"0",
      "id":"1"
   }]
}

Here no data for custom_261 is returned.

Any help would be much appreciated.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: API not returning custom data
August 01, 2013, 05:30:59 am
Please see this text on http://wiki.civicrm.org/confluence/display/CRMDOC42/Using+Custom+Data+with+the+API :

Quote
Generally, custom data is accessed through API v3 by use of parameters which include the unique id of the custom field. e.g. custom_22. As with normal API parameters, you can set custom_22 = 'Fred' in a get operation to filter for records that have custom_22 set to Fred, and you can make sure you get the custom field returned by setting the parameter return.custom_22 = 1.

CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API not returning custom data
August 01, 2013, 05:43:31 am
Hi,

is contact 1 having anything in the custom field? we tend to remove empty params in return.

try adding a id=7857 to be sure you test with a contact that has a custom field

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

Jacob Hilton

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.2.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.30-30.2
  • PHP version: 5.2.17
Re: API not returning custom data
August 01, 2013, 06:35:34 am
Thanks very much for your replies. Unfortunately, the problem persists.

For example, mysite/ajax/rest?json=1&sequential=1&debug=1&entity=Contact&action=get&id=7857&return=custom_261 returns:

{
   "is_error":0,
   "version":3,
   "count":1,
   "id":7857,
   "values":[{
      "contact_id":"7857",
      "id":"7857"
   }]
}

As you can see, no custom_261 data is returned, even though it exists for this contact as demonstrated in the original post and even though "return" was set to "custom_261".

Using the format "return.custom_261"=>1 instead of "return"=>"custom_261" in the PHP script does not seem to help either. Furthermore, attempting to sort data e.g. using "sort"=>"custom_261 ASC" returns the error message "DB Error: no such field".

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: API not returning custom data
August 01, 2013, 06:50:43 am
If you are using "CiviCRM version: 4.2.3" then I would recommend you upgrade to 4.3.5 and see if that fixes this.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API not returning custom data
August 11, 2013, 02:33:16 pm
Hmm - sounds like it might be worth checking to see if we have a unit test that covers passing in custom fields & no other fields as a return param - I feel like I may have seen this behaviour before
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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

This forum was archived on 2017-11-26.