Gravity Forms REST API v2 Beta 1 Released
By Steve Henty Published November 23, 2016Update 30 December 2016: see the release notes for Gravity Forms REST API v2 Beta 2.
The Gravity Forms REST API version 2.0-beta-1 is now available on the downloads page. This a developer-focused, feature plugin which contains version 2 of the current Web/REST API and it will ultimately become part of the Gravity Forms core.
The aim of version 2 is to dovetail with the WordPress REST API in terms of routing, discovery, authentication, usage, extensibility and best practices. It also provides the solid foundation we need for the development of future versions of Gravity Forms and add-ons.
Version 2 will work alongside version 1 but users will have the option to turn off version 1. Support for version 1 will be phased out so it’s very important that developers begin adding support for version 2 now.
Please send all your bug reports, questions and comments by opening a support ticket. The development version of the plugin can be found in the public repository on GitHub.
Upgrading to Version 2
The API is largely the same as the current version 1. The endpoints are the same and the same signature authentication mechanism is still supported alongside WordPress cookie authentication.
The following breaking changes are required by clients to consume version 2:
Content-Type
The API accepts both standard form fields and JSON content types. When sending JSON, the content-type request header must be set to “application/json”. If the content-type is omitted then the request will be interpreted as “application/x-www-form-urlencoded”.
No Response Envelope
The response will not be enveloped by default as in version 1. This means that the response will not be a JSON string containing the “status” and “response” – the body will contain the response and the HTTP code will contain the status code.
The WP-API will envelope the response if the _envelope parameter is included in the request.
WordPress Cookie Authentication Nonce
The “gf_api” nonce is no longer supported. Use the WordPress cookie authentication provided by the WP API instead. Create the nonce using wp_create_nonce( ‘wp_rest’ ) and send it in the _wpnonce data parameter (either POST data or in the query for GET requests), or via the X-WP-Nonce header.
Form Submissions
The Form Submissions endpoint now accepts application/json, application/x-www-form-urlencoded and multipart/form-data content types. With the introduction of support for the multipart/form-data content type files can be sent to single file upload fields.
Request values should be sent all together instead of in separate elements for input_values, field_values, target_page and source_page.
Example body of a JSON form submission:
{
"input_1": "test",
"field_values" : "",
"source_page": 1,
"target_page": 0
}
POST Single Resources
In order to maintain consistency with the WP API, the POST /entries and POST /forms endpoints no longer accept collections. This means that it’s no longer possible to create multiple entries or forms in a single request.
For further technical details, check out the readme.md file in the plugin folder.