Answers.Body: <p>The wiki page <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/REST+interface" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/REST+interface</a> pretty much describe what you could do with rest.</p>
  
  <p>From the wiki page :</p>
  
  <blockquote>
    <p>Before the REST interface can be used, two things have to be set up:</p>
    
    <ul>
    <li>You need to know your site key which can be found in the    civicrm.settings.php file labelled CIVICRM_SITE_KEY.</li>
    <li>You will need to enter an API key for every user that will be allowed to use the REST interface. (See below)</li>
    </ul>
  </blockquote>
  
  <p>Then you will have to call an url like :</p>
  
  <pre><code>https://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?entity=event&amp;action=get&amp;key=your_site_key&amp;api_key=the_user_api_key&amp;json=1
  </code></pre>
  
  <ul>
  <li>Option <code>json=1</code> will give you result in json format instead of xml</li>
  <li>You may need to use <code>&amp;options[limit]=xxx</code> if you want more than 25 results</li>
  </ul>
  
  <p>Every options available in the api should be available in REST but need to be converted in the proper URL syntax. The wiki page give you some good examples of standard api call vs REST api call.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T14:33:07.790Z
Answers.Text: Thanks for your reply, I have already seen that link.
  
  All I don't understand is the code.
  
  As per this link: http://wiki.civicrm.org/confluence/display/CRMDOC42/REST+interface
Answers.UserDisplayName: Parth Vora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T18:26:56.193Z
Answers.Text: The link you give is for CiviCRM <= 4.2, please use the link i gave for a more recent version. What code don't you understand exactly ?
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T08:12:02.510Z
Answers.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?
Answers.UserDisplayName: Parth Vora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T09:03:42.513Z
Answers.Text: The error 'Failed to authenticate key' indicates that the 'key' parameter in your request does not match the CIVICRM_SITE_KEY in the remote site's civicrm.settings.php file.
Answers.UserDisplayName: davejenx
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-22T13:38:21.933Z
Answers.LastActivityDate: 2015-07-22T13:38:21.933Z
Answers.UserDisplayName: samuelsov
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>
  
  <ol>
  <li><p>Option 1: </p>
  
  <pre><code>$api = new civicrm_api3(array ('server' =&gt; 'http://localhost/abc',
      'api_key'=&gt;'123456789',
      'key'=&gt;'123xyzABC'));
  </code></pre></li>
  <li><p>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></li>
  </ol>
  
  <p>Is there any other options. I want to go for option 1 if that is possible. And I want response in JSON if possible.</p>
  
Tags: <rest><drupal>
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. And I want response in JSON if possible.
  
  **Tags:** rest, drupal
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-22. Score: 2
  
  The wiki page <http://wiki.civicrm.org/confluence/display/CRMDOC/REST+interface> pretty much describe what you could do with rest.
  
  From the wiki page :
  
  > Before the REST interface can be used, two things have to be set up:
  >
  > * You need to know your site key which can be found in the civicrm.settings.php file labelled CIVICRM\_SITE\_KEY.
  > * You will need to enter an API key for every user that will be allowed to use the REST interface. (See below)
  
  Then you will have to call an url like :
  
  ```
  https://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?entity=event&action=get&key=your_site_key&api_key=the_user_api_key&json=1
  
  ```
  
  * Option `json=1` will give you result in json format instead of xml
  * You may need to use `&options[limit]=xxx` if you want more than 25 results
  
  Every options available in the api should be available in REST but need to be converted in the proper URL syntax. The wiki page give you some good examples of standard api call vs REST api call.
  
  > **Comments:**
  > **username_0**: Thanks for your reply, I have already seen that link.  All I don't understand is the code.  As per this link: http://wiki.civicrm.org/confluence/display/CRMDOC42/REST+interface  
  > **username_1**: The link you give is for CiviCRM <= 4.2, please use the link i gave for a more recent version. What code don't you understand exactly ?  
  > **username_0**: $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_2**: The error 'Failed to authenticate key' indicates that the 'key' parameter in your request does not match the CIVICRM_SITE_KEY in the remote site's civicrm.settings.php file.  
  
  ---
  
  