Sorry if I'm being thick here, but I've looked and looked. Is there an API call to get the contact id of the logged-in user?

What I need to do is check whether an activity has been authored by the logged in user (in order to show or hide an edit button, in an angular extension).

If there is a way of restricting people from editing (but not from viewing) CiviCase activities that weren't created by them, that would be even better, but I fear it will be easier to do the above.


  • 1
    This would be useful! Have you seen checkPerm() function? It might not be fine-grained enough for your needs, but ... Check eg ang/crmMailing/EditMailingCtrl.js and ang/crmMailing/EditMailingCtrl/workflow.html. It seems to read CRM.permissions which is populated on page load? Apr 3, 2016 at 23:41

2 Answers 2


In case of an angular page use something like

function myext_civicrm_angularModules(&$angularModule) {
  $session =& CRM_Core_Session::singleton();
  drupal_add_js(array('CurrentCiviUid' => $session->get('userID')), 'setting');

and access it in JS:

var uid = Drupal.settings.CurrentCiviUid;

For a Javascript-only solution, you can also make an API call using user_contact_id for the contact ID. For instance:

$result = civicrm_api3('Contact', 'get', [
  'sequential' => 1,
  'return' => ["id"],
  'id' => "user_contact_id",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.