Answers.Body: <p>Option one: API will be the best option </p>
  
  <p>Please use this link in your instance 
  <a href="http://localhost/abc/civicrm/api/explorer" rel="nofollow">http://localhost/abc/civicrm/api/explorer</a>
  or 
  <a href="http://d46.demo.civicrm.org/civicrm/api/explorer#explorer" rel="nofollow">http://d46.demo.civicrm.org/civicrm/api/explorer#explorer</a></p>
  
  <p>you will get JSON output </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T14:27:44.340Z
Answers.Text: Thanks for your reply, I have already seen those links. All I don't understand is the code. As per this link:
  http://wiki.civicrm.org/confluence/display/CRMDOC42/REST+interface First thing is to login: $test = simplexml_load_file("https://<your site>/sites/all/modules/civicrm/extern/rest.php?q=civicrm/login&name=Erik Hommel&pass=<password>&key=<site key>");
  foreach ($test->children() as $kids) { $apikey = $kids->api_key; $sessionid = $kids->PHPSESSID;
  } Query:
  But what should be the value of "name" and "pass" parameters? Are those the credentials of a Drupal user with admin role (whic
Answers.UserDisplayName: Parth Vora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T16:15:34.587Z
Answers.Text: yes,  name and pass are credentials of drupal user with admin right
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T08:30:56.017Z
Answers.Text: @parthvora : Please first try getting the value in the browser (address bar)                 http://localhost/abc/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":999}/drupal_test/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":999}&api_key=999&key=123abc
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T09:26:31.227Z
Answers.Text: I have tried below links directly into browser address bar as you suggested: http://localhost/abc/sites/all/modules/civicr ​m/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":123456789}&a ​pi_key=123456789&key=123xyzABC http://localhost/abc/sites/all/modules/civicr ​m/extern/rest.php?entity=Contact&action=get&json={"sequential":1}&a ​pi_key=123456789&key=123xyzABC But I'm getting this: **Unable to parse returned JSON**
Answers.UserDisplayName: Parth Vora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T14:00:53.287Z
Answers.LastActivityDate: 2015-07-22T14:00:53.287Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.Body: <p>It's probably easiest to use a wrapper around that call that hide the complexity.</p>
  
  <p>You can copy api/class.api.php into your client server and use it as indicated in the example in the source:</p>
  
  <pre><code> $api = new civicrm_api3 (array ('server' =&gt; 'http://example.org',
                                  'api_key'=&gt;'theusersecretkey',
                                  'key'=&gt;'thesitesecretkey'));
  
  if $api-&gt;Contact-&gt;Get(array(
   'contact_type'=&gt;'Individual',
   'last_name' =&gt; 'koot',
   'return'=&gt;'sort_name,current_employer')) 
  {
    // each key of the result array is an attribute of the api
    echo "\n contacts found " . $api-&gt;count;
    foreach ($api-&gt;values as $c) {
      echo "\n".$c-&gt;sort_name. " working for ". $c-&gt;current_employer;
    }
    // in theory, doesn't append
  } else {
    echo $api-&gt;errorMsg();
  }
  </code></pre>
  
  <p>should fetch from the remote civicrm server and let you do the needed with the data on your client server</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T08:37:20.710Z
Answers.LastActivityDate: 2015-07-23T08:37:20.710Z
Answers.UserDisplayName: Xavier
Body: <p>I'm new to CiViCRM. I want to fetch events which are created in CiViCRM which is hosted on another server. So basically I want to fetch CiViCRM data from one individual site to my site. I don't know that which are the ways to do it and which is the best one. But I think Rest option would be good if I'm not wrong. I'm not able to find any similar example which is near to my task. All I don't understand that how should I use my rest url with code:</p>
  
  <p>1) Option 1: </p>
  
  <p>$api = new civicrm_api3(array ('server' => '<a href="http://localhost/abc" rel="nofollow">http://localhost/abc</a>',</p>
  
  <p>'api_key'=>'123456789',
    'key'=>'123xyzABC'));</p>
  
  <p>2) Option 2:</p>
  
  <pre><code> $contactxml =       simplexml_load_file("http://localhost/abc/sites/all/modules/civicrm/extern /rest.php?entity=contact&amp;action=get&amp;key=&lt;site    key&gt;&amp;api_key=$apikey&amp;last_name=Koot");
    foreach ($contactxml-&gt;children() as $contact) {
      $display = $contact-&gt;display_name;
    }
  </code></pre>
  
  <p>Is there any other options. I want to go for option 1 if that is possible. How to get response in JSON?</p>
  
  <p>Any help would be appreciated.    </p>
  
  <p>Thanks</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-23T08:14:36.203Z
Comments.Text: $test = simplexml_load_file('http://localhost/xyz/sites/all/modules/contrib/civicrm/extern/rest.php/entity=Event&action=get&json="sequential":1}&api_key=123456789&key=123xyzABC');
  print_r($test);exit; For above code I'm getting this:
  SimpleXMLElement Object ( [Result] => SimpleXMLElement Object ( [error_message] => Failed to authenticate key [is_error] => 1 ) ) both keys are also correct. What I'm doing wrong here?
Comments.UserDisplayName: Parth Vora
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-23T09:01:54.553Z
Comments.Text: @Xavier
  I have tried that too:
  module_load_include('php', 'civicrm', '../api/class.api'); $api = new civicrm_api3 (array ('server' => 'http://localhost/abc', 'api_key'=>'123456789', 'key'=>'123xyzABC')); if($api->Event->Get(array('sequential'=>1))) { // each key of the result array is an attribute of the api echo "\n contacts found " . $api->count; foreach ($api->values as $c) { echo "\n".$c->sort_name. " working for ". $c->current_employer; } // in theory, doesn't append
  } else { echo $api->errorMsg();
  }
  exit; // */ It gives me:
  **Unable to parse returned JSON**
Comments.UserDisplayName: Parth Vora
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-23T16:06:10.270Z
Comments.Text: Please edit your question or add comments when you have more information that could help resolve the problem. Answers should be reserved to describe a solution to the question asked.
Comments.UserDisplayName: samuelsov
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-24T09:13:38.733Z
Comments.Text: @samuelsov , Sorry for that. I'm new here. I thought if I change my original question, how you guys know about that modifications? Is there any automated notification or something like that?
Comments.UserDisplayName: Parth Vora
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-24T19:52:55.837Z
Comments.Text: No problem. Usually people add a bold "Edit" below the original text. If the question become too much of a back and forth discussion, then IRC or forum.civicrm.org is a better place.
Comments.UserDisplayName: samuelsov
Tags: <drupal><civicrm-home><rest>
Title: How to fetch CiViCRM events externally [ Drupal 7]
ThreadText: # How to fetch CiViCRM events externally [ Drupal 7]
  
  (Asked by: username_0 on 2015-07-22)
  
  I'm new to CiViCRM. I want to fetch events which are created in CiViCRM which is hosted on another server. So basically I want to fetch CiViCRM data from one individual site to my site. I don't know that which are the ways to do it and which is the best one. But I think Rest option would be good if I'm not wrong. I'm not able to find any similar example which is near to my task. All I don't understand that how should I use my rest url with code:
  
  1) Option 1:
  
  $api = new civicrm\_api3(array ('server' => '<http://localhost/abc>',
  
  'api\_key'=>'123456789',
  'key'=>'123xyzABC'));
  
  2) Option 2:
  
  ```
   $contactxml =       simplexml_load_file("http://localhost/abc/sites/all/modules/civicrm/extern /rest.php?entity=contact&action=get&key=<site    key>&api_key=$apikey&last_name=Koot");
    foreach ($contactxml->children() as $contact) {
      $display = $contact->display_name;
    }
  
  ```
  
  Is there any other options. I want to go for option 1 if that is possible. How to get response in JSON?
  
  Any help would be appreciated.
  
  Thanks
  
  **Tags:** drupal, civicrm-home, rest
  
  > **Comments:**
  > **username_1**: $test = simplexml_load_file('http://localhost/xyz/sites/all/modules/contrib/civicrm/extern/rest.php/entity=Event&action=get&json="sequential":1}&api_key=123456789&key=123xyzABC'); print_r($test);exit; For above code I'm getting this: SimpleXMLElement Object ( [Result] => SimpleXMLElement Object ( [error_message] => Failed to authenticate key [is_error] => 1 ) ) both keys are also correct. What I'm doing wrong here?  
  > **username_1**: @username_4 I have tried that too: module_load_include('php', 'civicrm', '../api/class.api'); $api = new civicrm_api3 (array ('server' => 'http://localhost/abc', 'api_key'=>'123456789', 'key'=>'123xyzABC')); if($api->Event->Get(array('sequential'=>1))) { // each key of the result array is an attribute of the api echo "\n contacts found " . $api->count; foreach ($api->values as $c) { echo "\n".$c->sort_name. " working for ". $c->current_employer; } // in theory, doesn't append } else { echo $api->errorMsg(); } exit; // */ It gives me: **Unable to parse returned JSON**  
  > **username_2**: Please edit your question or add comments when you have more information that could help resolve the problem. Answers should be reserved to describe a solution to the question asked.  
  > **username_1**: @username_2 , Sorry for that. I'm new here. I thought if I change my original question, how you guys know about that modifications? Is there any automated notification or something like that?  
  > **username_2**: No problem. Usually people add a bold "Edit" below the original text. If the question become too much of a back and forth discussion, then IRC or forum.civicrm.org is a better place.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2015-07-22. Score: 2
  
  Option one: API will be the best option
  
  Please use this link in your instance
  <http://localhost/abc/civicrm/api/explorer>
  or
  <http://d46.demo.civicrm.org/civicrm/api/explorer#explorer>
  
  you will get JSON output
  
  > **Comments:**
  > **username_1**: Thanks for your reply, I have already seen those links. All I don't understand is the code. As per this link: http://wiki.civicrm.org/confluence/display/CRMDOC42/REST+interface First thing is to login: $test = simplexml_load_file("https://<your site>/sites/all/modules/civicrm/extern/rest.php?q=civicrm/login&name=Erik Hommel&pass=<password>&key=<site key>"); foreach ($test->children() as $kids) { $apikey = $kids->api_key; $sessionid = $kids->PHPSESSID; } Query: But what should be the value of "name" and "pass" parameters? Are those the credentials of a Drupal user with admin role (whic  
  > **username_3**: yes,  name and pass are credentials of drupal user with admin right  
  > **username_3**: @username_1 : Please first try getting the value in the browser (address bar)                 http://localhost/abc/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":999}/drupal_test/sites/all/modules/civicrm/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":999}&api_key=999&key=123abc  
  > **username_1**: I have tried below links directly into browser address bar as you suggested: http://localhost/abc/sites/all/modules/civicr ​m/extern/rest.php?entity=Contact&action=get&json={"sequential":1,"api_key":123456789}&a ​pi_key=123456789&key=123xyzABC http://localhost/abc/sites/all/modules/civicr ​m/extern/rest.php?entity=Contact&action=get&json={"sequential":1}&a ​pi_key=123456789&key=123xyzABC But I'm getting this: **Unable to parse returned JSON**  
  
  ---
  
  ### Answer by username_4 on 2015-07-23. Score: 2
  
  It's probably easiest to use a wrapper around that call that hide the complexity.
  
  You can copy api/class.api.php into your client server and use it as indicated in the example in the source:
  
  ```
   $api = new civicrm_api3 (array ('server' => 'http://example.org',
                                  'api_key'=>'theusersecretkey',
                                  'key'=>'thesitesecretkey'));
  
  if $api->Contact->Get(array(
   'contact_type'=>'Individual',
   'last_name' => 'koot',
   'return'=>'sort_name,current_employer')) 
  {
    // each key of the result array is an attribute of the api
    echo "\n contacts found " . $api->count;
    foreach ($api->values as $c) {
      echo "\n".$c->sort_name. " working for ". $c->current_employer;
    }
    // in theory, doesn't append
  } else {
    echo $api->errorMsg();
  }
  
  ```
  
  should fetch from the remote civicrm server and let you do the needed with the data on your client server
  
  
  ---
  
  