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) »
  • Standard way of accessing custom fields data via API calls?
Pages: [1]

Author Topic: Standard way of accessing custom fields data via API calls?  (Read 626 times)

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Standard way of accessing custom fields data via API calls?
October 17, 2011, 04:37:59 pm
Yep, me again, sorry for making a mess of these boards, but here it goes:

I have the following coming back from an API call:
Code: [Select]
{"is_error":0,"version":3,"count":1,"id":2,"values":{"2":{"id":"2","membership_id":"2","contact_id":"49346","membership_contact_id":"49346","membership_type_id":"2","join_date":"2011-10-03","start_date":"2011-10-03","membership_start_date":"2011-10-03","end_date":"2012-11-02","membership_end_date":"2012-11-02","status_id":"1","owner_membership_id":"1","is_test":"0","member_is_test":"0","is_pay_later":"0","member_is_pay_later":"0","membership_name":"Corporate","relationship_name":"Employee of","custom_6":"2","custom_6_2":"2","api_membership_get":{"is_error":0,"version":3,"count":1,"id":1,"values":[{"id":"1","contact_id":"49734","membership_type_id":"2","join_date":"2011-10-03","start_date":"2011-10-03","end_date":"2012-11-02","status_id":"1","is_test":"0","is_pay_later":"0","membership_name":"Corporate","relationship_name":"Employee of","custom_6":"2","custom_6_1":"2","related_contact_id":"49346"}]}}}}

I've made a custom field group + a single read only field for every membership type I'm working with.
The value holds the number of people per membership that can attend events at a "members only" price.

My current problem is that I can't seem to think of a way to dynamically map the key names (custom_X) to membership type IDs (or any other value for that matter). I got lucky with a few where membership_type_id $N matched custom_$N, but I just ran a few tests that proved that will not work...

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Standard way of accessing custom fields data via API calls?
October 17, 2011, 10:29:28 pm
Most of the getfields action will returns the custom fields (eg their name/label as well as their id). Not sure if event.getfields is already working, but that would be easy to fix if not the case.

the membershiptype.get will get your the other part of the equation. if you can find a way of matching the two by their name/label, should work.

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Standard way of accessing custom fields data via API calls?

This forum was archived on 2017-11-26.