Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-17413

Can't determine logged-in cid during a REST call

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.4.13
    • Fix Version/s: 4.7
    • Component/s: CiviCRM API
    • Labels:
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      When a user is logged in normally, you can get the active Civi contact ID with:

      $session = CRM_Core_Session::singleton();
      $cid = $session->get('userID');
      

      and the active Drupal one with:

      global $user;
      $uid = $user->uid;
      

      During a REST call, for example in a custom API or a hook, the first is not available- the session variable has not been set. The Drupal uid is available, even though the Civi cid must have been known to get it, because API keys are attached to a Civi contact.

      This was demonstrated in custom code from FF and a fix found with help from Tim Otten. PR to follow.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              DaveFF David Knoll
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: