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 know my contact id using the API
Pages: [1]

Author Topic: How to know my contact id using the API  (Read 657 times)

hvelarde

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.5.0
  • CMS version: Drupal
  • MySQL version: NA
  • PHP version: NA
How to know my contact id using the API
October 07, 2014, 01:50:35 pm
I'm working on collective.civicrm, an add-on to integrate CiviCRM with Plone, a Python-based CMS.

my implementation stores the URL and the key of the CiviCRM, and the API key of every user.

right now I have implemented a contact search form, quite similar to the basic search form of CiviCRM; I can also select contacts on the results and see more information on them like relationships and activities.

one of the new features I need to implement is adding an activity and that's why I'm asking if it is possible to know the contact id using only the API key.

does anybody else have found a similar use case? how do you solve it?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How to know my contact id using the API
October 07, 2014, 02:42:16 pm
Interesting project. I'm curious to know why you don't just go the full Monty and really integrate CiviCRM with Plone. The size of the integration code for, say, Wordpress and CiviCRM is tiny (only a couple thousand lines of code total).
Try asking your question on the new CiviCRM help site.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: How to know my contact id using the API
October 08, 2014, 09:28:30 am
@colemans, probably because it's different languages, it's likely to be on different servers, hence the REST interface.

api_key is filtered quite a bit, you unfortunately can't do a contact.get (api_key:"whatyouseek"). I would create a new extension (use civix to generate the boilerplate) that implements a new api getcurrent. creating that api is simply putting a file api/v3/Contact/Getcurrent.php that contains function civicrm_api3_contact_getcurrent

check other in the api/v3 in civi to give you an idea of the syntax.

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

hvelarde

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.5.0
  • CMS version: Drupal
  • MySQL version: NA
  • PHP version: NA
Re: How to know my contact id using the API
October 08, 2014, 11:05:33 am
thank you, Xavier; that makes a lot of sense.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How to know my contact id using the API
October 08, 2014, 02:13:07 pm
I'm fairly sure the source contact defaults to 'user_contact_id' when creating an activity. This value is barely documented (feel free to take that as a challenge) but is generally translated to the logged in user's contact id during api calls
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: How to know my contact id using the API
October 09, 2014, 12:28:12 am
Another trick Eileen reminded me of: instead of putting the id of the contact id, put the string  'user_contact_id' and it will default to the logged in one.
(the magic is in _civicrm_api3_validate_integer)

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

hvelarde

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.5.0
  • CMS version: Drupal
  • MySQL version: NA
  • PHP version: NA
Re: How to know my contact id using the API
October 13, 2014, 06:38:16 am
thanks! I'll test it...

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to know my contact id using the API

This forum was archived on 2017-11-26.