Answers.Body: <p>I got the issue. It was due to .htaccess authentication on entire site.</p>
  
  <p>In such <strong>access denied</strong> cases, CiViCRM API should give some proper response message like "Access denied" or "Authentication failure" instead of just <strong>Unable to parse returned JSON</strong> </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T14:56:52.163Z
Answers.Text: Good suggestion. A pull-request to improve the error handling would be most welcome.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-30T10:18:19.303Z
Answers.Text: how did you solve this issue
Answers.UserDisplayName: Bhuvnesh Gupta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-30T14:54:18.693Z
Answers.LastActivityDate: 2015-07-30T14:54:18.693Z
Answers.UserDisplayName: Parth Vora
Body: <p>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. </p>
  
  <p>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:</p>
  
  <p><strong>Unable to parse returned JSON</strong></p>
  
  <p>All configuration is perfect e.i API key, site key and CiVi server.</p>
  
  <p>Below is my code to fetch events using API. </p>
  
  <pre><code>$api = new civicrm_api3 (array ('server' =&gt; 'http://xxxxxxx.com', 'api_key'=&gt; 'abc123456', 'key'=&gt; 'd0d792e6cd3c824bb3e0b671992fdc2d'));
  
  if ($api-&gt;Event-&gt;Get()) {
      print_r($api);
  } else {
      echo $api-&gt;errorMsg();
  }
  </code></pre>
  
  <p>PS: I don't think there can be any issue in code, as same code is working fine on local.</p>
  
  <p>Any help would be appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-30T13:44:28.347Z
Comments.Text: What is the returned response from the remote server? My guess is it's a 403 or 404.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-30T14:20:09.603Z
Comments.Text: It just prints **Unable to parse returned JSON** nothing else, how can I check that what its the error code here?
Comments.UserDisplayName: Parth Vora
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-30T14:44:49.327Z
Comments.Text: You'll need to stick a print_r() or similar inside the civicrm_api3 class to get the full server response.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-30T14:55:30.533Z
Comments.Text: @Coleman, print_r() is not printing any response code. Anyway I got the issue here.  Thanks.
Comments.UserDisplayName: Parth Vora
Tags: <civievent><drupal><api>
Title: Unable to parse returned JSON - CiViCRM
ThreadText: # Unable to parse returned JSON - CiViCRM
  
  (Asked by: username_0 on 2015-07-30)
  
  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.
  
  **Tags:** civievent, drupal, api
  
  > **Comments:**
  > **username_1**: What is the returned response from the remote server? My guess is it's a 403 or 404.  
  > **username_0**: It just prints **Unable to parse returned JSON** nothing else, how can I check that what its the error code here?  
  > **username_1**: You'll need to stick a print_r() or similar inside the civicrm_api3 class to get the full server response.  
  > **username_0**: @username_1, print_r() is not printing any response code. Anyway I got the issue here.  Thanks.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-07-30. Score: 2 | Accepted answer
  
  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**
  
  > **Comments:**
  > **username_1**: Good suggestion. A pull-request to improve the error handling would be most welcome.  
  > **username_2**: how did you solve this issue  
  
  ---
  
  