CiviCRM WP REST API Wrapper¶
APIv3 Deprecation
API version 3 is now deprecated. Version 4 is recommended.
Starting in CiviCRM Version 5.25 CiviCRM's extern scripts have been exposed as WordPress REST endpoints.
Requirements:
- PHP 7.1+
- WordPress 4.7+
- CiviCRM version 5.25
Endpoints¶
-
civicrm/v3/rest
- a wrapper aroundcivicrm_api3()
Parameters:
key
- required, the site keyapi_key
- required, the contact api keyentity
- required, the API entityaction
- required, the API actionjson
- optional, json formatted string with the API parameters/arguments, or1
as injson=1
It mimics CiviCRM's REST interface, by default all calls to
civicrm/v3/rest
return XML formatted results. To getjson
formatted results passjson=1
or a json formatted string with the API parameters, like in example 2 below.Examples:
-
https://example.com/wp-json/civicrm/v3/rest?entity=Contact&action=get&key=<site_key>&api_key=<api_key>&group=Administrators
-
https://example.com/wp-json/civicrm/v3/rest?entity=Contact&action=get&key=<site_key>&api_key=<api_key>&json={"group": "Administrators"}
-
civicrm/v3/url
- a substitution forcivicrm/extern/url.php
to track when links in mailings are clicked. -
civicrm/v3/open
- a substitution forcivicrm/extern/open.php
to track when recipients open mailings. -
civicrm/v3/authorizeIPN
- a substitution forcivicrm/extern/authorizeIPN.php
(for testing Authorize.net as per docs)Note: this endpoint has not been tested
-
civicrm/v3/ipn
- a substitution forcivicrm/extern/ipn.php
(for PayPal Standard and Pro live transactions)Note: this endpoint has not been tested
-
civicrm/v3/cxn
- a substitution forcivicrm/extern/cxn.php
-
civicrm/v3/pxIPN
- a substitution forcivicrm/extern/pxIPN.php
Note: this endpoint has not been tested
-
civicrm/v3/widget
- a substitution forcivicrm/extern/widget.php
-
civicrm/v3/soap
- a substitution forcivicrm/extern/soap.php
Note: this endpoint has not been tested
Settings¶
It is recommened to use the hook included in the code to replace the mailing url via the WP REST API. To do this create a plugin that includes the following:
add_filter( 'civi_wp_rest/plugin/replace_mailing_tracking_urls', '__return_true' )
Creating a standalone functionality plugin is recommended. You can read the WP docs on Writing a plugin, there is a good tutorial on a Functionality Plugin at ccs-tricks
Alternatively, but not recommended. you can set the CIVICRM_WP_REST_REPLACE_MAILING_TRACKING
constant to true
to replace mailing url and open tracking calls with their counterpart REST endpoints, civicrm/v3/url
and civicrm/v3/open
.
Note: use this setting with caution, it may affect performance on large mailings, see CiviCRM_WP_REST\Civi\Mailing_Hooks
class.