I know there's been a lot of work to deprecate the extern
endpoints in CiviCRM, and the extern
endpoints don't work in Drupal 8 without a lot of finagling. The documentation isn't updated to reflect a new way of using D8 REST endpoints, nor is API Explorer. Does anyone know what the "correct" endpoint is?
-
1I think this is still in flux so need to add the word "today" on the end of the question (grin). See also lab.civicrm.org/dev/core/-/issues/2077 and github.com/civicrm/civicrm-core/pull/17952– DemeritCommented Oct 11, 2020 at 18:51
2 Answers
I just installed a CiviCRM and Drupal 9 instance (5.40.1). These were my steps:
- I enabled the new authx extension
cv ext:enable authx
- I allowed the authenticate with the api_key in a special header
cv ev 'Civi::settings()->set("authx_xheader_cred",["api_key"]);'
The auth extension does not have a configuration screen, yet. - I added site key as an extra protection
cv ev 'Civi::settings()->set("authx_guards",["site_key"]);'
. - I flushed the CiviCRM cache
cv flush
And now the following CURL command can be used to call the REST api:
curl -X GET --location "http://<<server>>/civicrm/ajax/rest?
entity=Contact&action=get&json=1" \
-H "X-Civi-Auth: Bearer <<api_key>>" \
-H "X-Civi-Key: <<site_key>>" \
-H "Accept: application/json" \
-H "X-Requested-With: XMLHttpRequest"
My previous answer here is now out dated. Now the endpoint is /civicrm/ajax/rest
. But first you must enable the AuthX extension (Administer menu » System Settings » Extensions). Then you'll have an Authentication menu at Administer menu » System Settings » Authentication. There is a link to documentation from there that provides instructions for more complex workflows.
-
I used a symbolic link to
<drupal root>/vendor/civicrm/civicrm-core/extern
in<drupal root>/web/libraries/civicrm/core
since that will, I hope, make sure that the folder remains in date. i Commented May 5, 2021 at 17:03