Answers.Body: <p>Turns out the problem was that I was calling curl without putting quotes around the url.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-21T11:46:12.827Z
Answers.LastActivityDate: 2018-03-21T11:46:12.827Z
Answers.UserDisplayName: mnieber
Answers.Body: <p>This error is generally thrown due to error in the site key included in the rest URL. Double check the following things in your API -</p>
  
  <ul>
  <li>Param assigned to <code>key</code> should be equal to <code>CIVICRM_SITE_KEY</code> specified in civicrm.settings.php. </li>
  <li><p>Make sure you're checking the correct setting file and value.</p></li>
  <li><p><code>CIVICRM_SITE_KEY</code> should be greater than 7 characters.</p></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-21T10:04:32.233Z
Answers.Text: As far as I know, I only have one settings file. I'm now trying to print messages to the error log, but I have no clue to which log file civicrm is writing these messages.
Answers.UserDisplayName: mnieber
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-21T08:59:07.063Z
Answers.LastActivityDate: 2018-03-21T08:59:07.063Z
Answers.UserDisplayName: jitendra - fuzion
Body: <p>I used the API explorer to create a target url, but I cannot send a GET request with curl. The error is: "Failed to authenticate key".</p>
  
  <p>Here are the steps I am following:</p>
  
  <ol>
  <li>Create an url in the API explorer:</li>
  </ol>
  
  <p><a href="http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=userkey&amp;key=sitekey&amp;json=" rel="nofollow noreferrer">http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=userkey&amp;key=sitekey&amp;json=</a>{"sequential":1}</p>
  
  <ol start="2">
  <li><p>Looked up the site key in civicrm.settings.php (under <code>CIVICRM_SITE_KEY</code>)</p></li>
  <li><p>Used the "API Key" extention to add an API key to the "admin" contact (the one that is associated with the civicrm admin account).</p></li>
  <li><p>I inserted my keys (which I change here for security reasons) to produce this expanded url:</p></li>
  </ol>
  
  <p><a href="http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=uCMXIUhzpPv&amp;key=VKtUrOkd&amp;json=" rel="nofollow noreferrer">http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&amp;action=get&amp;api_key=uCMXIUhzpPv&amp;key=VKtUrOkd&amp;json=</a>{"sequential":1}</p>
  
  <ol start="5">
  <li>I <code>curl</code> this url, and get the mentioned error</li>
  </ol>
  
  <p>Can anybody help?</p>
  
  <h2>UPDATE</h2>
  
  <p>I was able to stick a debug log statement into the <code>authenticateKey</code> function of <code>System.php</code>:</p>
  
  <pre><code>CRM_Core_Error::debug_var("req", $_REQUEST);
  CRM_Core_Error::debug_var("req size", sizeof($_REQUEST));
  </code></pre>
  
  <p>The result of this is:</p>
  
  <pre><code>Mar 21 11:49:21  [info] $req = Array
  (
      [entity] =&gt; Contact
  )
  
  Mar 21 11:49:21  [info] $req size = 1
  </code></pre>
  
  <p>So it seems only the first key/val pair of the request is received in _REQUEST. How can this happen?</p>
  
Tags: <api><civicrm.settings.php>
Title: "Failed to authenticate key" when posting to REST api
ThreadText: # "Failed to authenticate key" when posting to REST api
  
  (Asked by: username_0 on 2018-03-20)
  
  I used the API explorer to create a target url, but I cannot send a GET request with curl. The error is: "Failed to authenticate key".
  
  Here are the steps I am following:
  
  1. Create an url in the API explorer:
  
  <http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=userkey&key=sitekey&json=>{"sequential":1}
  
  2. Looked up the site key in civicrm.settings.php (under `CIVICRM_SITE_KEY`)
  3. Used the "API Key" extention to add an API key to the "admin" contact (the one that is associated with the civicrm admin account).
  4. I inserted my keys (which I change here for security reasons) to produce this expanded url:
  
  <http://51.15.94.180/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&action=get&api_key=uCMXIUhzpPv&key=VKtUrOkd&json=>{"sequential":1}
  
  5. I `curl` this url, and get the mentioned error
  
  Can anybody help?
  
  ## UPDATE
  
  I was able to stick a debug log statement into the `authenticateKey` function of `System.php`:
  
  ```
  CRM_Core_Error::debug_var("req", $_REQUEST);
  CRM_Core_Error::debug_var("req size", sizeof($_REQUEST));
  
  ```
  
  The result of this is:
  
  ```
  Mar 21 11:49:21  [info] $req = Array
  (
      [entity] => Contact
  )
  
  Mar 21 11:49:21  [info] $req size = 1
  
  ```
  
  So it seems only the first key/val pair of the request is received in \_REQUEST. How can this happen?
  
  **Tags:** api, civicrm.settings.php
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-03-21. Score: 2 | Accepted answer
  
  Turns out the problem was that I was calling curl without putting quotes around the url.
  
  
  ---
  
  ### Answer by username_1 on 2018-03-21. Score: 1
  
  This error is generally thrown due to error in the site key included in the rest URL. Double check the following things in your API -
  
  * Param assigned to `key` should be equal to `CIVICRM_SITE_KEY` specified in civicrm.settings.php.
  * Make sure you're checking the correct setting file and value.
  * `CIVICRM_SITE_KEY` should be greater than 7 characters.
  
  > **Comments:**
  > **username_0**: As far as I know, I only have one settings file. I'm now trying to print messages to the error log, but I have no clue to which log file civicrm is writing these messages.  
  
  ---
  
  