0

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}

  1. Looked up the site key in civicrm.settings.php (under CIVICRM_SITE_KEY)

  2. Used the "API Key" extention to add an API key to the "admin" contact (the one that is associated with the civicrm admin account).

  3. 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}

  1. 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?

2

Turns out the problem was that I was calling curl without putting quotes around the url.

0

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.

  • 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. – mnieber Mar 21 '18 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.