2

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.

  • 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. – Parth Vora Jul 29 '15 at 13:19
4

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.

  • Yeah, good thing to watch out for when copying contacts from one database to another. – Andrew Hunt Jul 30 '15 at 14:50
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.

  • 1
    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. – Parth Vora Jul 30 '15 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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