Answers.Body: <p>API keys are set manually per contact in the civicrm_contact table, so it's possible that you haven't set the key for your contact in your new installation.</p>
  
  <p>If that's set, you also need to make sure the contact with the key corresponds to a user with permission to view events:</p>
  
  <ol>
  <li><p>Find the contact in CiviCRM and see if it has a User ID listed next to its contact ID on the contact summary.</p></li>
  <li><p>If not, check to see if there's a Drupal user with that contact's email address. If you find one, you'll need to resync contacts to users (found in the CiviCRM Administer menu).</p></li>
  <li><p>If you don't find a user with that address, create one. Confirm that the user is connected to the contact by viewing the contact summary again. If it hasn't connected, you may need to merge.</p></li>
  <li><p>Once you have a user connected to the contact with the API key set, make sure they have the right permissions--a role with at least "Access CiviCRM", "Access CiviEvent", and "View all events" granted.</p></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T11:22:54.857Z
Answers.Text: Thanks a lot @Andrew Hunt, but the actual problem was that there were **two** CiVi contacts having the same API key set, and one of them was connected with Drupal user but another **wasn't**, so that was the main issue here.
Answers.UserDisplayName: Parth Vora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-29T13:49:07.480Z
Answers.LastActivityDate: 2015-07-29T13:49:07.480Z
Answers.UserDisplayName: Andie Hunt
Answers.Body: <p>Actual problem was that there were two CiVi contacts having the same API key set, and one of them was connected with Drupal user but another wasn't, so that was the main issue here.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T14:50:02.070Z
Answers.Text: Yeah, good thing to watch out for when copying contacts from one database to another.
Answers.UserDisplayName: Andie Hunt
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T11:27:30.453Z
Answers.LastActivityDate: 2015-07-31T12:06:31.500Z
Answers.LastEditDate: 2015-07-31T12:06:31.500Z
Answers.UserDisplayName: Parth Vora
Body: <p>I have just installed a fresh CiViCRM 4.6.5 with new Drupal setup. I'm trying to fetch all events from CiViCRM.</p>
  
  <pre><code>$api = new civicrm_api3 (array ('server' =&gt; 'http://localhost/civicrm', 'api_key'=&gt;'123456789', 'key'=&gt;'82666e3fdc5cc88c6c31ddbef2a74cxx'));
  
  // Get all events from CiViCRM
  if ($api-&gt;Event-&gt;get()) {
      print_r($api);
  } else {
      echo $api-&gt;errorMsg();
  }
  exit;
  </code></pre>
  
  <p>Any idea how to solve above issue?</p>
  
  <p>Any help would be appreciated. Thanks.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-29T13:19:55.277Z
Comments.Text: By the way before I was using CiVi version 4.6.4 and above code was working fine with that. So might be an issue with latest version.
Comments.UserDisplayName: Parth Vora
Tags: <drupal><api><permissions>
Title: ERROR: No CMS user associated with given api-key
ThreadText: # ERROR: No CMS user associated with given api-key
  
  (Asked by: username_0 on 2015-07-29)
  
  I have just installed a fresh CiViCRM 4.6.5 with new Drupal setup. I'm trying to fetch all events from CiViCRM.
  
  ```
  $api = new civicrm_api3 (array ('server' => 'http://localhost/civicrm', 'api_key'=>'123456789', 'key'=>'82666e3fdc5cc88c6c31ddbef2a74cxx'));
  
  // Get all events from CiViCRM
  if ($api->Event->get()) {
      print_r($api);
  } else {
      echo $api->errorMsg();
  }
  exit;
  
  ```
  
  Any idea how to solve above issue?
  
  Any help would be appreciated. Thanks.
  
  **Tags:** drupal, api, permissions
  
  > **Comments:**
  > **username_0**: By the way before I was using CiVi version 4.6.4 and above code was working fine with that. So might be an issue with latest version.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2015-07-30. Score: 4 | Accepted answer
  
  Actual problem was that there were two CiVi contacts having the same API key set, and one of them was connected with Drupal user but another wasn't, so that was the main issue here.
  
  > **Comments:**
  > **username_1**: Yeah, good thing to watch out for when copying contacts from one database to another.  
  
  ---
  
  ### Answer by username_1 on 2015-07-29. Score: 3
  
  API keys are set manually per contact in the civicrm\_contact table, so it's possible that you haven't set the key for your contact in your new installation.
  
  If that's set, you also need to make sure the contact with the key corresponds to a user with permission to view events:
  
  1. Find the contact in CiviCRM and see if it has a User ID listed next to its contact ID on the contact summary.
  2. If not, check to see if there's a Drupal user with that contact's email address. If you find one, you'll need to resync contacts to users (found in the CiviCRM Administer menu).
  3. If you don't find a user with that address, create one. Confirm that the user is connected to the contact by viewing the contact summary again. If it hasn't connected, you may need to merge.
  4. Once you have a user connected to the contact with the API key set, make sure they have the right permissions--a role with at least "Access CiviCRM", "Access CiviEvent", and "View all events" granted.
  
  > **Comments:**
  > **username_0**: Thanks a lot @Andrew username_1, but the actual problem was that there were **two** CiVi contacts having the same API key set, and one of them was connected with Drupal user but another **wasn't**, so that was the main issue here.  
  
  ---
  
  