Answers.Body: <p>After more digging in response to my Ajax check in a browser I found a question: <a href="https://civicrm.stackexchange.com/questions/41967/how-can-i-call-api-directly-from-external-http">How can I call api directly from external http?</a>, that didn't answer my question, but referenced the AuthX extension. I thought I would take a look at my sites' extension lists.</p>
  <p>The sites that weren't talking to me did not have the AuthX CiviCRM extension installed and the ones that were communicating, did. After installing the AuthX extension, the site would talk to me without any further configuration.</p>
  <p>I do not know what underlying services or restrictions are involved, but this provided a path through. Hopefully this is useful to some other searcher (maybe future me).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-24T09:28:10.160Z
Answers.Text: AuthX is a civiCRM Extension. At first I thought it was a PHP extension, but after following your link I found out it can simply be installed over civiCRM's "Extensions" in the web-panel. Thanks for the question and answer!
Answers.UserDisplayName: mplh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-14T13:47:23.373Z
Answers.LastActivityDate: 2023-05-25T13:17:55.080Z
Answers.LastEditDate: 2023-05-25T13:17:55.080Z
Answers.UserDisplayName: kapn
Body: <p>I've recently started using the check_civicrm script from <a href="https://github.com/MegaphoneJon/check_civicrm" rel="nofollow noreferrer">https://github.com/MegaphoneJon/check_civicrm</a></p>
  <p>It works great and my monitoring is greatly improved. However, on some sites I get a 403 error instead of expected response from CiviCRM. I successfully determined that the earlier 500 errors were due to lack of anonymous permission on &quot;CiviCRM: access AJAX API&quot;.</p>
  <p>Adding to the mystery is the fact that two of the installations are on the same server. One gives expected output, the other a 403. I assume there is some additional permission required somewhere, but I am at a loss to figure out what.</p>
  <p>The Civi log is not particularly edifying either, just telling me <code>Civi\API\Exception\UnauthorizedException: &quot;Authorization failed&quot;</code></p>
  <p><strong>UPDATE:</strong> I have dug into the script and see that is is making a POST request to <a href="https://sitename.com/civicrm/ajax/api4/System/check" rel="nofollow noreferrer">https://sitename.com/civicrm/ajax/api4/System/check</a>. When I visit it in a browser I get a 401 error and the message <code>&quot;Ajax requests can only be issued by javascript clients, eg. CRM.api4().&quot;</code>.</p>
  <p>Any thoughts?</p>
  
Tags: <api><permissions>
Title: Nagios script returns 403 error when querying CiviCRM via Ajax API
ThreadText: # Nagios script returns 403 error when querying CiviCRM via Ajax API
  
  (Asked by: username_0 on 2023-04-13)
  
  I've recently started using the check\_civicrm script from <https://github.com/MegaphoneJon/check_civicrm>
  
  It works great and my monitoring is greatly improved. However, on some sites I get a 403 error instead of expected response from CiviCRM. I successfully determined that the earlier 500 errors were due to lack of anonymous permission on "CiviCRM: access AJAX API".
  
  Adding to the mystery is the fact that two of the installations are on the same server. One gives expected output, the other a 403. I assume there is some additional permission required somewhere, but I am at a loss to figure out what.
  
  The Civi log is not particularly edifying either, just telling me `Civi\API\Exception\UnauthorizedException: "Authorization failed"`
  
  **UPDATE:** I have dug into the script and see that is is making a POST request to <https://sitename.com/civicrm/ajax/api4/System/check>. When I visit it in a browser I get a 401 error and the message `"Ajax requests can only be issued by javascript clients, eg. CRM.api4()."`.
  
  Any thoughts?
  
  **Tags:** api, permissions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-04-14. Score: 2 | Accepted answer
  
  After more digging in response to my Ajax check in a browser I found a question: [How can I call api directly from external http?](https://civicrm.stackexchange.com/questions/41967/how-can-i-call-api-directly-from-external-http), that didn't answer my question, but referenced the AuthX extension. I thought I would take a look at my sites' extension lists.
  
  The sites that weren't talking to me did not have the AuthX CiviCRM extension installed and the ones that were communicating, did. After installing the AuthX extension, the site would talk to me without any further configuration.
  
  I do not know what underlying services or restrictions are involved, but this provided a path through. Hopefully this is useful to some other searcher (maybe future me).
  
  > **Comments:**
  > **username_1**: AuthX is a civiCRM Extension. At first I thought it was a PHP extension, but after following your link I found out it can simply be installed over civiCRM's "Extensions" in the web-panel. Thanks for the question and answer!  
  
  ---
  
  