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) »
  • How to get employer_id from the API?
Pages: [1]

Author Topic: How to get employer_id from the API?  (Read 477 times)

samknelson

  • I’m new here
  • *
  • Posts: 6
  • Karma: 1
  • CiviCRM version: 4.6.4
  • CMS version: Drupal 7
  • MySQL version: 4.5
  • PHP version: 5.4
How to get employer_id from the API?
September 09, 2015, 05:00:14 am
I'm having trouble getting the empoyer_id from the API.  On the public API explorer,

http://dmaster.demo.civicrm.org/civicrm/api/explorer#explorer

$result = civicrm_api3('Contact', 'get', array(
  'sequential' => 1,
  'id' => 25,
));

outputs the employer name, but not the employer ID.  When I try to do a getvalue on the specific field -- listed as one of the options:

$result = civicrm_api3('Contact', 'getvalue', array(
  'sequential' => 1,
  'return' => "employer_id",
  'id' => 25,
));


it throws a "field employer_id unset or not existing".  I can go straight to the database, but I'd rather do it through the API.  Any hints?  Thank you!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How to get employer_id from the API?
September 09, 2015, 02:01:12 pm
The contact api is a bit random because it uses the BAO Query object rather than the api-query-code.  If you don't feel  like going there & submitting a patch your options are

1) submit a unit test instead - if someone submits a JIRA on the api with a test we try pretty hard to fix them
2) use the relationship api instead - since you know the relationship type & there is 'usually' only one
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

samknelson

  • I’m new here
  • *
  • Posts: 6
  • Karma: 1
  • CiviCRM version: 4.6.4
  • CMS version: Drupal 7
  • MySQL version: 4.5
  • PHP version: 5.4
Re: How to get employer_id from the API?
September 10, 2015, 06:10:37 am
Thanks for your answer, Eileen.  I'll try to submit a patch.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to get employer_id from the API?

This forum was archived on 2017-11-26.