The current documentation for creating an API key for user is on the wiki at https://wiki.civicrm.org/confluence/display/CRMDOC/REST+interface#RESTinterface-CreatingAPIkeysforusers. Unfortunately there is not a release for the user friendly API Key extension for CiviCRM 4.5, 4.6 or 4.7. And the manual method is not very user friendly for those who are not programmers. How can a relatively non-technical user set up an API key that is needed for an extension, for example?
3 Answers
Hopefully a new release will be made for the API Key extension soon. Here are detailed instructions for creating one manually without needing to get access to your database through phpMyAdmin, mysql on the command line or some similar MySQL database administration tool.
Usually it is a good idea to create a special separate contact for each service that needs to use CiviCRM's REST API. Do this at Contact > New Individual, enter a name like Attentive.ly Service, and click Save. At the bottom of your page in small faint type and in the url you can get the Contact ID of the new contact.
Create a 16 character random value for the API Key, eg at http://passwordsgenerator.net/ with settings that exclude special characters, eg
Now use your CiviCRM installation's API explorer to set the API key for your user. Navigate to Support > Developer > Api Explorer v4. Enter the following and click Execute:
For those wanting to use APIv3, navigate to Support > Developer > Api v3 (/civicrm/api3#explorer), and enter the following values then click on the Execute button. Note that the image shows Internal Contact ID as the fieldname. This is true CiviCRM up to version 4.6, but you'll need to select the Contact ID for versions 4.7 and above since it was relabeled in the API Explorer.
You will need to ensure that the contact is given a role that has the appropriate permissions required for the relevant Extension. At a minimum this will include 'Access AJAX API', and unless otherwise specified, 'Administer CiviCRM'.
-
Very nice! For completeness, please mark this as answered. Also, 4.7 changes things just slightly. The field "Internal Contact ID" is seen as "Contact ID." Additionally, don't forget to hit Execute to apply the changes.– G HMar 14, 2016 at 14:47
-
-
1Does this need to mention that a User needs creating and eg in Drupal it might be easier to 'create new user' and get the civi contact as a result?– petednz - fuzion ♦Feb 16, 2017 at 2:30
You need to use the extension which creates an 'API Key' tab on the contact record.
https://github.com/cividesk/com.cividesk.apikey/archive/v1.0.zip
JMC
To add an API key to an existing contact in API Explorer v4:
navigate to Support > Developer > API Explorer v4.
In the "entity" drop-down menu select "contact", in the "action" drop-down select "update".
In the "where" section select "id" from the "add clause" drop-down and make that equal to the contact id of the contact that you wish to add the API key to.
In the "values" section select api_key from the "add value" drop-down and add your desired API key to the box that appears next to it.
click the execute button.