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) »
  • i don't know how to get the contact_id from the logged user by rest interface
Pages: [1]

Author Topic: i don't know how to get the contact_id from the logged user by rest interface  (Read 638 times)

crazy_bitch

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
i don't know how to get the contact_id from the logged user by rest interface
April 09, 2013, 09:13:18 am
Hi, i am new in the forum and i am having problems using the api rest, when i log in using the url:
myroot/civicrm/extern/rest.php?q=civicrm/login&name=user&pass=password
i get my api_key and my key but if i want to create an activity with the logged user how i can get his contact_id to pass it to the post petition? because i have been looking around the rest interface and i don't know how can i get the contac_id from the civicrm having just the drupal username and the password.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: i don't know how to get the contact_id from the logged user by rest interface
April 09, 2013, 10:24:54 am
I haven't tried it myself, but after skimming the source-code, this might work: instead of using a numerical contact ID, use the string "user_contact_id", e.g. "&source_contact_id=user_contact_id&assignee_contact_id=user_contact_id". This should be automatically adapted based on the current Drupal user.

(Note: it looks like "user_contact_id" is supported in Civi 4.2 and 4.3 but not older versions.)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: i don't know how to get the contact_id from the logged user by rest interface
April 09, 2013, 11:32:46 am
Do you have the drupal user?

you can use the uf_match entity


http://example.crm/sites/all/modules/civicrm/extern/rest.php?entity=UFMatch&action=getsingle&debug=1&sequential=1&json=1&uf_name={drupallogin}&api_key={yoursitekey}&key={yourkey}

and take it from there

Code: [Select]
{
"id":"1",
"domain_id":"1",
"uf_id":"1",
"uf_name":"drupallogin",
"contact_id":"2",
"language":"en_US",
}


You can probably as well chain the uf_match get with the api.activity.create so you create the activity directly (you need the latest version of civi so the chaining work over rest probably)
« Last Edit: April 09, 2013, 11:35:52 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

crazy_bitch

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: i don't know how to get the contact_id from the logged user by rest interface
April 10, 2013, 12:44:24 am
Thanks a lot guys, each solution has solve the problem ;D

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • i don't know how to get the contact_id from the logged user by rest interface

This forum was archived on 2017-11-26.