Answers.Body: <p>You may need to add below line in .htaccess or nginx config to allow php file be executed</p>
  <pre><code>RewriteCond %{REQUEST_URI} !/libraries/civicrm/extern/[a-z]+\.php$
  </code></pre>
  <p><a href="https://civicrm.stackexchange.com/a/37956/155">Copy extern directory from civicrm vendor folder into libraries</a></p>
  <p>The rest api url for drupal would look like</p>
  <pre><code>https://sitename/libraries/civicrm/core/extern/rest.php
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-04T22:08:16.767Z
Answers.LastActivityDate: 2021-05-04T22:08:16.767Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I am trying to work out a way of presenting contact information from CiviCRM to another server, but am struggling to work out how one would code it. Has anyone got an example of something that works under Drupal 9?</p>
  <pre><code>Running https://&lt;server root&gt;/civicrm/ajax/rest?entity=Contact&amp;action=get&amp;api_key=Userkey&amp;key=Sitekey&amp;json={%22contact_type%22:%22Individual%22,%22first_name%22:%22&lt;firstname%22,%22last_name%22:%22lastname22}
  </code></pre>
  <p>gives</p>
  <pre><code>{&quot;IP&quot;:&quot;fe80::e00a:1010:c022:f80e%9&quot;,&quot;level&quot;:&quot;security&quot;,&quot;referer&quot;:null,&quot;reason&quot;:&quot;CSRF suspected&quot;,&quot;is_error&quot;:1,&quot;error_message&quot;:&quot;SECURITY ALERT: Ajax requests can only be issued by javascript clients, eg. CRM.api3().&quot;}
  </code></pre>
  <p>so clearly it needs to be called from javascript, presumably on the client.</p>
  <p>It would be really helpful if someone had an example of a working script.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-05T01:04:37.863Z
Comments.Text: See also https://github.com/civicrm/civicrm-core/pull/19727 and https://lab.civicrm.org/dev/core/-/issues/2077
Comments.UserDisplayName: Demerit
Tags: <api><javascript><rest>
Title: Has anyone got a recent example of a REST client under Drupal 9, possibly using AJAX?
ThreadText: # Has anyone got a recent example of a REST client under Drupal 9, possibly using AJAX?
  
  (Asked by: username_0 on 2021-05-04)
  
  I am trying to work out a way of presenting contact information from CiviCRM to another server, but am struggling to work out how one would code it. Has anyone got an example of something that works under Drupal 9?
  
  ```
  Running https://<server root>/civicrm/ajax/rest?entity=Contact&action=get&api_key=Userkey&key=Sitekey&json={%22contact_type%22:%22Individual%22,%22first_name%22:%22<firstname%22,%22last_name%22:%22lastname22}
  
  ```
  
  gives
  
  ```
  {"IP":"fe80::e00a:1010:c022:f80e%9","level":"security","referer":null,"reason":"CSRF suspected","is_error":1,"error_message":"SECURITY ALERT: Ajax requests can only be issued by javascript clients, eg. CRM.api3()."}
  
  ```
  
  so clearly it needs to be called from javascript, presumably on the client.
  
  It would be really helpful if someone had an example of a working script.
  
  **Tags:** api, javascript, rest
  
  > **Comments:**
  > **username_1**: See also https://github.com/civicrm/civicrm-core/pull/19727 and https://lab.civicrm.org/dev/core/-/issues/2077  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-05-04. Score: 1
  
  You may need to add below line in .htaccess or nginx config to allow php file be executed
  
  ```
  RewriteCond %{REQUEST_URI} !/libraries/civicrm/extern/[a-z]+\.php$
  
  ```
  
  [Copy extern directory from civicrm vendor folder into libraries](https://civicrm.stackexchange.com/a/37956/155)
  
  The rest api url for drupal would look like
  
  ```
  https://sitename/libraries/civicrm/core/extern/rest.php
  
  ```
  
  
  ---
  
  