Caldera Forms, beginning in version 1.5, provides a REST API for form configurations and entries. The primary role of the Caldera Forms REST API, at this time, is to provide data to the Front-end entry viewer.
As of version 1.5, this API is read only and requires authorization — by default as an admin. Filters are provided to modify permissions or implement alternative permission schemes.
The base URL for all API endpoints is: wp-json/cf-api/v2
You can perform the following requests:
- /forms
- GET Form configuration (does not include processor configuration) for many forms.
- /forms/<form-id>
- GET Form configuration (does not include processor configuration) for a form.
- /forms/<form-id>/revisions
- GET Form configuration revisions.
- Added in Caldera Forms 1.5.3
- /entries/form-id/
- GET Entries for a specific form.
- /entries/form-id/entry-id
- GET An entry from a form.
- /entries/form-id/entry-id
- DELETE A specific entry.
Caldera Forms REST API Permissions
By default all requests require that the current user by authorized, via standard WordPress authentication methods as an admin to view entries. There are many filters to modify this, and a special token system for granting access to lower roles.
Changing Permissions For The Caldera Forms REST
Filter documentation coming soon.
Control What Data Is Exposed Via The Caldera Forms REST
By default all fields are returned by the Caldera Forms REST API. You can prevent fields from being added to REST API responses using the caldera_forms_api_show_field filter.
The Caldera Forms JavaScript REST API Client
Caldera Forms provides a JavaScript client for interacting with its REST API.
Loading The Caldera Forms REST API Client
There are some useful PHP classes you can use to help set up this JavaScript client’s loading and to help print needed configuration information to the DOM using wp_localize_script().
The setup is slightly different if you want to allow this instance of the API client to be used by non-admin users. For admin-only, you can skip setting up the special access token, and use this:
If you wish to add an access token for lower user levels, this is how you would set up script loading:
In both cases, you probably also want to add your own JavaScript file here, using wp_enqueue_script().
Using The Caldera Forms REST API Client
Before using the Caldera Forms REST API client, you must initialize it, per form, using the CFAPI function. Presuming you have followed the first example in the previous section, for using the API for admin users only, you can initialize the API client like this:
If you have followed the first example in the previous section, for using the API for users of a lower role than admin, you can initialize the API client like this:
The object that this returns has very simple methods for getting form configuration and form entry data: