Changes between Version 12 and Version 13 of CiviCRM HowTo Use Rest API


Ignore:
Timestamp:
08/30/13 15:10:45 (11 years ago)
Author:
Richard Bramley
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CiviCRM HowTo Use Rest API

    v12 v13  
    2929=== Authentication
    3030
    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.
     31In order to authenticate you need the site key from above and an api_key for your user account.
     32
     33You have to create an api_key in MySQL using the following script:
     34
     35{{{#!sql
     36update civicrm_contact set api_key='<api-key>' where id='<id>';
     37}}}
     38
     39It'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{{{
     44http://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
     47The rest API can be used with the older syntax of
     48
     49{{{
     50http://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
     53or even
     54
     55{{{
     56http://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
     59These alternatives being provided to help muddy the water and add as must extra code and confusion as possible.
    3260
    3361=== Options
     
    4169* The data returned can be restricted using the parameter {{{&return=f1,f2...etc}}}, where fn is a field returned in the JSON.
    4270
    43 An example: http://lcbru.xuhl-tr.nhs.uk/civicrm/ajax/rest?fnName=civicrm/contact/get&json=1&key={SITE_KEY}&name={USERNAME}&pass={PASSWORD}
    44