GravityView REST API endpoints
GravityView has a read-only REST API at /wp-json/gravityview/v1/ on your site. Developers use it to list Views, read a View’s entries as JSON, HTML, CSV or TSV, and load the next results of a View on a page without reloading the page.
The endpoints for Views and entries return data only after you allow REST access. The refresh endpoint follows its own rules, and Refreshing a View on the page explains them.
Allowing REST access #
REST access is off by default. You can turn it on for every View, or for one View at a time.
To turn it on for every View:
- Go to GravityKit, then Settings.
- Click GravityView Pro, then General.
- Turn on REST API and click Save Settings.

To turn it on for one View:
- Edit the View and scroll to the Settings box.
- Click Permissions.
- Turn on Allow REST Access and click Update.

Allow REST Access shows while the REST API setting is off. While REST API is on, the same tab has Prevent REST Access instead, which keeps that one View out of the API.
A View without REST access returns 403 with “You are not allowed to view this content.” A signed-in user who can edit the View gets “REST API access is disabled for this View.” with a link to the setting. Reasons for the “You are not allowed to view this content.” message covers the other causes.
The View’s other settings still apply. Entries the View hides, such as unapproved entries on a View that shows only approved ones, are left out. Visitors get 403 from a View with Prevent Direct Access on, even with REST access.
Listing your Views #
GET /wp-json/gravityview/v1/viewsThis endpoint lists your published Views, newest first. Anyone can call it.
| Parameter | What it does | Default |
|---|---|---|
page | The page of results | 1 |
limit | The number of Views per page | 10 |
The response has views, a list of Views, and total, the number of published Views. Each View has its ID, title, form ID, layout (template_id), fields and widgets.
A signed-in user who can edit other users’ Views, which GravityView lets administrators do by default, also gets each View’s settings and search_criteria. A user who can edit Gravity Forms forms also gets the View’s form.
For a View without REST access, the list shows its ID and the message “You are not allowed to view this content.” in post_content.
To get one View, add its ID:
GET /wp-json/gravityview/v1/views/123Getting a View’s entries #
GET /wp-json/gravityview/v1/views/123/entries.jsonThis endpoint lists the entries View 123 shows, 10 at a time, whatever the View’s Number of entries per page is. For HTML, CSV or TSV, replace .json with .html, .csv or .tsv. Without an extension, you get JSON.
| Parameter | What it does | Default |
|---|---|---|
page | The page of results | 1 |
limit | The number of entries per page. 0 returns every entry. | 10 |
post_id | The ID of a page that embeds the View. With the ID of a page that doesn’t embed it, the endpoint returns 404. | None |
use_labels | With 1, a CSV or TSV file has field labels in its first row. Without it, the first row has field IDs. | None |
The View’s own search and sort parameters work the same way they do in the View’s address. For example:
filter_2=Kitchensearches field 2 when field 2 is in the View’s Search Bar.gv_search=Austinsearches with Search Everything when the Search Bar has it.sort[4]=descsorts by field 4 when Enable sorting by column is on.
GravityView ignores a search parameter for a field the Search Bar doesn’t have.
A JSON response has each entry’s values by field ID, and the total number of entries:
GET /wp-json/gravityview/v1/views/123/entries.json?limit=2{
"entries": [
{ "1": "Omar Haddad", "2": "Front desk", "3": "Tucson", "4": "13" },
{ "1": "Grace Murphy", "2": "Delivery", "3": "Madison", "4": "5" }
],
"total": 12
}Each entry has the fields of the View’s Multiple Entries layout. The gravityview/rest/entry/fields filter adds or removes fields, such as date_created.
A field inside a Repeater field returns a list with one value per row of the Repeater. A Name, Address or Product field inside it returns one object per row, by input ID:
{
"1": "Lakeshore Public Library",
"11": [
{ "11.3": "Maya", "11.6": "Okafor" },
{ "11.3": "Daniel", "11.6": "Brooks" }
],
"13": [ "Full day", "Morning workshops" ]
}The Repeater field itself returns its rows, with each row’s values by field ID, or by input ID for a field with several inputs, such as 11.3 and 11.6 for the first and last name.
It leaves out the fields set to Hidden in Gravity Forms, returns the fields set to Administrative only to users who can edit Gravity Forms entries, and follows the field’s Maximum results setting. Showing Repeater fields in a View has more about Repeaters in a View.
The other formats return:
- For
.html, a JSON string that holds the View’s HTML. TheX-Item-Countheader has the number of entries in the response, andX-Item-Totalthe number in the View. - For
.csvand.tsv, a file download named after the View’s title.
The HTML uses the View’s own layout. To render REST requests with another template, check for a REST request in the gravityview/template/view/class filter and return that template’s class.
To get one entry, add its ID, with .json or .html at the end. The response has the fields of the View’s Single Entry layout. A request for an entry the View doesn’t show returns 404.
GET /wp-json/gravityview/v1/views/123/entries/456.jsonRefreshing a View on the page #
GET /wp-json/gravityview/v1/views/123/refreshThis endpoint returns one page of View 123’s results for the search, sort and page in its query string. GravityView uses it to change a View’s results on the page without reloading the page. A DataTables View loads every page of its table through it.
The REST API, Allow REST Access and Prevent REST Access settings control the Views and entries endpoints above. The refresh endpoint is how the page itself loads a View’s results, so it returns only what a visitor to that page could see, and works with REST access off.
Views it returns results for
The endpoint returns results for a View that refreshes on the page:
- A View that shows its entries with DataTables
- A View that shows its entries on a map with Maps
- A View with Live Filters
- A View you turn on with a filter, as shown below
For any other View, it returns 404 with “Not found.”, the same as for a View that doesn’t exist.
Turning it on for a View
The gk/gravityview/view/refresh/live filter decides whether a View refreshes on the page. When it returns true for a View, the endpoint returns that View’s results, and the View’s page loads GravityView’s script for refreshing it.
This snippet turns it on for View 123. Change 123 to your View’s ID:
/**
* Refreshes View 123 on the page and lets the refresh endpoint return its results.
*
* @param bool $live Whether the View refreshes on the page.
* @param \GV\View $view The View being rendered or refreshed.
*
* @return bool Whether the View refreshes on the page.
*/
add_filter( 'gk/gravityview/view/refresh/live', function ( $live, $view ) {
return 123 === (int) $view->ID ? true : $live;
}, 10, 2 );Note: Adding custom PHP code snippets to your website explains where this code goes.
To turn on the endpoint for a View and leave its page as it is, return true from gk/gravityview/view/refresh/enabled instead.
Parameters
| Parameter | What it does | Default |
|---|---|---|
pagenum or page | The page of results. When a request has both, page is used. | 1 |
limit | The number of entries, from 1 to 200 | The View’s Number of entries per page |
post_id, embed, embed_state | The values in the View’s data-gv-scope attribute on the page. A View with Prevent Direct Access on needs them. | None |
gv_search_view | The ID of the View a search is for. A search with another View’s ID is ignored. | None |
Search and sort parameters work the same way as on the entries endpoint above. To change the 200-entry limit, use the gk/gravityview/view/refresh/max-page-size filter.
The response
{
"total": 12,
"page": { "current": 2, "first": 6, "last": 10 },
"entries_html": "<div id=\"gv-view-123-1\" class=\"gv-themed gv-theme-vantage gv-template-table\">…",
"facets": []
}totalis the number of entries that match the request.pagehas the page number and the positions of the first and last entries shown. After the last page,firstandlastare0.entries_htmlis the View’s HTML for that page. For a DataTables View, the response hasdatatablesin its place, an object with the table’s rows indataand the entry counts inrecordsTotalandrecordsFiltered.facetshas the Live Filters choices with their counts, or an empty list.- For a Maps View, the response also has
markers.
For a visitor who isn’t signed in, the response has the header Cache-Control: private, no-store, max-age=0. For a signed-in user, WordPress replaces it with Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private.
Developers can add their own parts to the response with gk/gravityview/view/refresh/parts, and leave out entries_html with gk/gravityview/view/refresh/render-entries.
Access rules
A request gets the results the person making it could see on the page:
- A visitor who isn’t signed in gets the results of any published View the endpoint serves. Entries the View hides, such as unapproved entries on a View that shows only approved ones, are left out.
- A private View returns
403with “You are not allowed to access this content.”, unless the request comes from a user who can see private Views, such as an administrator. - A View with Prevent Direct Access on returns results only when the request sends the page’s
post_id,embedandembed_statevalues, or comes from a user who can see private Views. With nopost_id, or the ID of a page that doesn’t embed the View, it returns404. With the ID of the embedding page and no matchingembed_state, it returns403with “This page is out of date or no longer available to you. Reload the page. If this keeps happening, clear the site’s page cache.” - A View with Enhanced Security on returns results without its secret, as the View’s own address does. The secret protects shortcodes and blocks.
Making requests as a signed-in user #
Without credentials, every request runs as a visitor who isn’t signed in. To make a request as a user, choose one of these:
- From a page on your site, send a REST nonce in an
X-WP-Nonceheader. A View that refreshes on the page has one in itsdata-gv-nonceattribute when the visitor is signed in. - From outside your site, use an Application Password for the user.
For a visitor who isn’t signed in, data-gv-nonce is empty. Send no X-WP-Nonce header then, because WordPress returns 403 with “Cookie check failed” for a nonce that isn’t valid.
Authentication in the WordPress REST API Handbook explains both ways.
Other routes #
The API is read-only, and a POST, PUT, PATCH or DELETE request gets an error. The entries routes answer it with 401, 403 or 404. A View’s own address, such as /wp-json/gravityview/v1/views/123, answers it with 501 and the message “Endpoint Not Yet Implemented.”
Two more routes under /wp-json/gravityview/v1/ serve GravityView features: the Live Filters choices and the entry lightbox. This guide doesn’t cover them.