CiviCRM HowTo Use Rest API
Relevant Links for version 4.2
- Devlopers Guide API Reference
- API Reference
- Rest Interface
- Setting up a Site Key - necessary for Rest API.
- Test Server API Explorer
- Parameter list for Test Server - What parameters are available for each entity in the API.
Steps to Enable the Rest API
- Create a site key
- Create a user
- Enable the user to access the REST api
Create a Site Key
- Go to The Bit Mill
- Select Uppercase, Lowercase, Numbers, Punctuation
- Set Removals from selection as
- Set length to be
- Edit the CiviCRM Settings file.
- For the test server this is: uhlbriccsapp04:/var/local/civicrm/drupal/sites/default/civicrm.settings.php
Using the REST API
In order to authenticate you need the site key from above and an api_key for your user account.
You have to create an api_key in MySQL using the following script:
update civicrm_contact set api_key='<api-key>' where id='<id>';
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
display_name do, however. They did for me anyway.
The rest API can be used with the older syntax of
These alternatives being provided to help muddy the water and add as must extra code and confusion as possible.
Documentation is a bit sketchy about options. Here are a few things that appear to be true.
- The default maximum number of entities returned is 25
- The default maximum can be increased by including
&option.limit=nnnin the URL. A limit of zero returns all rows. The parameter
rowCountalso works (case sensitive). See here.
- An starting offset can be provided by including
&option.offset=nnnin the URL. The parameter
offseton its own also works. ibid.
- Sorting uses
&option.sort=fffffwhere fffff is the name of a field returned in the JSON. The parameter
sortcan also be used.
- The data returned can be restricted using the parameter
&return=f1,f2...etc, where fn is a field returned in the JSON.