2

I have setup CiViCRM in one Drupal site, and then from another Drupal site I'm fetching events from that first site. This entire thing is working fine in my local.

Now I have uploaded both sites on staging server. On one site, I have install CiViCRM from scratch (no relation with local CiViCRM) and new CiVi installation is completed successfully without any errors. But when I'm trying to fetch events using API, I'm getting this error:

Unable to parse returned JSON

All configuration is perfect e.i API key, site key and CiVi server.

Below is my code to fetch events using API.

$api = new civicrm_api3 (array ('server' => 'http://xxxxxxx.com', 'api_key'=> 'abc123456', 'key'=> 'd0d792e6cd3c824bb3e0b671992fdc2d'));

if ($api->Event->Get()) {
    print_r($api);
} else {
    echo $api->errorMsg();
}

PS: I don't think there can be any issue in code, as same code is working fine on local.

Any help would be appreciated.

4
  • What is the returned response from the remote server? My guess is it's a 403 or 404.
    – Coleman
    Commented Jul 30, 2015 at 13:44
  • It just prints Unable to parse returned JSON nothing else, how can I check that what its the error code here?
    – Parth Vora
    Commented Jul 30, 2015 at 14:20
  • You'll need to stick a print_r() or similar inside the civicrm_api3 class to get the full server response.
    – Coleman
    Commented Jul 30, 2015 at 14:44
  • @Coleman, print_r() is not printing any response code. Anyway I got the issue here. Thanks.
    – Parth Vora
    Commented Jul 30, 2015 at 14:55

1 Answer 1

2

I got the issue. It was due to .htaccess authentication on entire site.

In such access denied cases, CiViCRM API should give some proper response message like "Access denied" or "Authentication failure" instead of just Unable to parse returned JSON

2
  • Good suggestion. A pull-request to improve the error handling would be most welcome.
    – Coleman
    Commented Jul 30, 2015 at 14:56
  • how did you solve this issue Commented Jun 30, 2021 at 10:18

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.