Answers.Body: <p>In case of an angular page use something like</p>
  
  <pre><code>function myext_civicrm_angularModules(&amp;$angularModule) {
    [...]
    $session =&amp; CRM_Core_Session::singleton();
    drupal_add_js(array('CurrentCiviUid' =&gt; $session-&gt;get('userID')), 'setting');
    [...]
  }
  </code></pre>
  
  <p>and access it in JS:</p>
  
  <pre><code>var uid = Drupal.settings.CurrentCiviUid;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T18:37:37.103Z
Answers.LastActivityDate: 2016-04-05T18:37:37.103Z
Answers.UserDisplayName: nielo
Answers.Body: <p>For a Javascript-only solution, you can also make an API call using <code>user_contact_id</code> for the contact ID.  For instance:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', [
    'sequential' =&gt; 1,
    'return' =&gt; ["id"],
    'id' =&gt; "user_contact_id",
  ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-11T15:49:52.890Z
Answers.LastActivityDate: 2019-01-14T15:19:19.830Z
Answers.LastEditDate: 2019-01-14T15:19:19.830Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>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?</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>Cheers</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-03T23:41:06.977Z
Comments.Text: 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?
Comments.UserDisplayName: Chris Burgess
Tags: <api><javascript><angular>
Title: How to get contact id of logged-in user in JS API
ThreadText: # How to get contact id of logged-in user in JS API
  
  (Asked by: username_0 on 2016-03-31)
  
  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.
  
  Cheers
  
  **Tags:** api, javascript, angular
  
  > **Comments:**
  > **username_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?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-04-05. Score: 3
  
  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;
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2019-01-11. Score: 2
  
  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",
  ]);
  
  ```
  
  
  ---
  
  