31 | | There is some talk in the documentation about having to log in and then use a session ID to access the REST API. However, more recent documentation says to just post the username and password with every request. |
| 31 | In order to authenticate you need the site key from above and an api_key for your user account. |
| 32 | |
| 33 | You have to create an api_key in MySQL using the following script: |
| 34 | |
| 35 | {{{#!sql |
| 36 | update civicrm_contact set api_key='<api-key>' where id='<id>'; |
| 37 | }}} |
| 38 | |
| 39 | It's not straight forward to find the user as the unique_user_id column doesn't contain anything, certainly not the unique id of the user. The {{{sort_name}}} and {{{display_name}}} do, however. They did for me anyway. |
| 40 | |
| 41 | === Example Request |
| 42 | |
| 43 | {{{ |
| 44 | http://lcbru-test.xuhl-tr.nhs.uk/sites/all/modules/civicrm/extern/rest.php?entity=contact&action=get&json=1&key={site_key}&api_key={api_key} |
| 45 | }}} |
| 46 | |
| 47 | The rest API can be used with the older syntax of |
| 48 | |
| 49 | {{{ |
| 50 | http://lcbru-test.xuhl-tr.nhs.uk//sites/all/modules/civicrm/extern/rest.php?q=civicrm/contact/get&json=1&key={site_key}&api_key={api_key} |
| 51 | }}} |
| 52 | |
| 53 | or even |
| 54 | |
| 55 | {{{ |
| 56 | http://lcbru-test.xuhl-tr.nhs.uk//sites/all/modules/civicrm/extern/rest.php?fnName=civicrm/contact/get&json=1&key={site_key}&api_key={api_key} |
| 57 | }}} |
| 58 | |
| 59 | These alternatives being provided to help muddy the water and add as must extra code and confusion as possible. |