v1 Examples

v1 Examples

EntriesRetrieve EntriesRetrieve the latest 10 entries for a formRetrieve all entries for a formRetrieve entries sorted by a specific fieldRetrieve entries sorted ascendingRetrieve entries by statusRetrieve entries more recent than a specific dateRetrieve entries for a date rangeRetrieve entries using field filters (one condition)Retrieve entries using field filters (multiple conditions)Retrieve entries using field filters (contains condition)Retrieve entries using search criteria and field filtersRetrieve entries that have been readRetrieve all entries with pagingRetrieve a single entryRetrieve specific fields for a single entryRetrieve specific fields for multiple entriesCreate EntriesCreate EntriesCreate Entry for a Specific FormUpdate EntriesUpdate Single Entry (Create Entry Array Manually)Update Single Entry (Create Entry Array Using Existing Database Record)Update Entries (Create Entries Array Manually)Update Entries (Create Entries Array Using Existing Database Records)Delete EntriesDelete Multiple EntriesFormsRetrieve FormsRetrieve all active formsRetrieve a single formRetrieve multiple formsInsert FormsInsert a single formInsert form with the confirmation set to redirectInsert form with the confirmation set to pageInsert form with a conditional confirmationInsert form with notifications sent to a specific email addressInsert form with notification set to use an email fieldInsert form with notification set to use routingInsert multiple formsUpdate FormsUpdate multiple formsDelete FormsForm SubmissionsComplex FieldsSubmit a list field that has a single columnSubmit a list field that has multiple columnsSubmit a Multi-Select FieldPricing FieldsSingle Product FieldSingle Product Field With OptionOption Field as a Checkbox

This article includes more detailed examples of how to interact with the REST API v1, formerly called the Web API. It is a work in progress. More examples will be added over time.
Entries
Retrieve Entries
Retrieve the latest 10 entries for a form
The example below retrieves the 10 most recent entries for form id 28. Paging is set to 10 by default.
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273public static function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} $base_url = 'http://localhost/wpdev/gravityformsapi/';$api_key = 'your_api_key';$private_key = 'your_private_key';$method  = 'GET';$route = 'forms/28/entries';$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, $method, $route, $expires );$sig = self::calculate_signature( $string_to_sign, $private_key ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; $response = wp_remote_request( $url, array('method' => 'GET' ) ); if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    echo 'There was an error attempting to access the API.';    die();} $body_json = wp_remote_retrieve_body( $response );//results are in the "body" and are json encoded, decode them and put into an array$body = json_decode( $body_json, true ); $data            = $body['response'];$status_code     = $body['status'];$total           = 0;$total_retrieved = 0; if ( $status_code <= 202 ){    //entries retrieved successfully    $entries = $data['entries'];    $status  = $status_code;    $total              = $data['total_count'];    $total_retrieved    = count( $entries );}else {    //entry retrieval failed, get error information    $error_code         = $data['code'];    $error_message      = $data['message'];    $error_data         = isset( $data['data'] ) ? $data['data'] : '';    $status             = $status_code . ' - ' . $error_code . ' ' . $error_message . ' ' . $error_data;}//display results in a simple page?>

    

Results

    

Status Code:

    

Total Count:

    

Total Retrieved:

    

JSON Response:

    
    

         0 ) {            echo '

';            foreach ( $entries as $entry ){                echo '

';            }            echo '

Form ID Entry ID Date Created
' . $entry['form_id'] . ' ' . $entry['id'] . ' ' . $entry['date_created'] . '

';        }        ?>    


JavaScript
1234567891011121314151617181920212223242526272829303132333435363738
The response from this example will look like the following if successful:
1{"status":200,"response":{"total_count":"22","entries":[{"id":"171","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation2","2":"create entry x","3":"create entry 2","1.2":"","1.4":"","1.8":""},{"id":"170","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation1","2":"create entry x","3":"create entry with form id specified","1.2":"","1.4":"","1.8":""},{"id":"169","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation2","2":"create entry 2","3":"create entry 2","1.2":"","1.4":"","1.8":""},{"id":"168","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation1","2":"create entry","3":"create entry with form id specified","1.2":"","1.4":"","1.8":""},{"id":"167","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation2","2":"create entry 2","3":"create entry 2","1.2":"","1.4":"","1.8":""},{"id":"166","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation1","2":"create entry","3":"create entry with form id specified","1.2":"","1.4":"","1.8":""},{"id":"165","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation2","2":"create entry 2","3":"create entry 2","1.2":"","1.4":"","1.8":""},{"id":"164","form_id":"28","date_created":"2015-06-15 22:43:23","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":"","is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"active","1.3":"Manual","1.6":"Creation1","2":"create entry","3":"create entry with form id specified","1.2":"","1.4":"","1.8":""},{"id":"163","form_id":"28","date_created":"2015-07-01 20:03:09","is_starred":0,"is_read":1,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":null,"is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"spam","1.3":"July","1.6":"First","2":"test","1.2":"","1.4":"","1.8":"","3":""},{"id":"162","form_id":"28","date_created":"2015-06-24 20:01:31","is_starred":0,"is_read":0,"ip":"::1","source_url":"http://localhost/wpdev/?gf_page=preview&id=28","post_id":null,"currency":"USD","payment_status":null,"payment_date":null,"transaction_id":null,"payment_amount":null,"payment_method":null,"is_fulfilled":null,"created_by":"1","transaction_type":null,"user_agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0","status":"trash","1.3":"d5","1.6":"d5","2":"d5","1.2":"","1.4":"","1.8":"","3":""}]}}
If no entries are located for the specified form, the response will look like the following:
1{"status":200,"response":{"total_count":"0","entries":[]}}
Retrieve all entries for a form
To retrieve all entries for a form, you may specify the page size within the URL』s querystring. To do this, you may use the example above and add the querystring parameter 「&paging[page_size]=」 to the URL as in the example below. In this example, the size is set to 1000 since this form has very few entries. Because you may not have an idea of how many entries exist for a form, you could simply set the size to a very large number, or even run a query to get the entry count and then set the page_size greater than the count. To see more information about paging, check out the Paging section in the REST API v1 article.
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?paging[page_size]=1000
Retrieve entries sorted by a specific field
To retrieve entries and have them sorted by a specific field, you may specify the sorting key within the URL』s querystring. In the example below, field id 1.3 (first name field on this form) is used as the sort key. You may use field ids, or the set of available entry meta keys, like date_created, payment_status, created_by, etc. To see more information about sorting and which entry meta keys may be used, check out the Sorting section in the REST API v1 article.
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?sorting[key]=1.3
Retrieve entries sorted ascending
To retrieve entries and have them sorted ascending, instead of the default descending, you may specify the sorting direction within the URL』s querystring. In the example below, the direction is set to 「ASC」 for ascending. The results will be sorted by field id 1.3 ascending. In this case, by first name alphabetically. To see more information about sorting, check out the Sorting section in the REST API v1 article.
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?sorting[direction]=ASC
Retrieve entries by status
The example below retrieves entries that are currently in the trash. To see more information about retrieving entries with search criteria, check out the Search Criteria section the REST API v1 article.
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?search[status]=trash
Retrieve entries more recent than a specific date
The example below retrieves entries which have been created on 06/24/2014 or are newer.
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?search[start_date]=2015-06-24
Retrieve entries for a date range
The example below retrieves entries that were created on 06/15/2015 through 06/24/2015 (inclusive).
1http://localhost/wpdev/gravityformsapi/forms/28/entries/?search[start_date]=2015-06-15&search[end_date]=2015-06-24
Retrieve entries using field filters (one condition)
The example below retrieves entries where the last name field (id 1.6) is 「Draven」. The search field filters must be a JSON string. Create your array of search criteria, JSON-encode it, and then URL encode it. To see more information about using field filters, check out the Field Filters section in the REST API v1 article
PHP
1234567891011121314151617//create the field filter array with key, operator, value and place it inside another array$field_filters = array (                     array(                         'key'      => '1.6',                         'operator' => 'is',                         'value' => 'Draven'                     )                 ); //set field_filters to array$search['field_filters'] = $field_filters; //convert the array to a JSON string and url encode it so the JSON formatting persists$search_json = urlencode( json_encode( $search ) ); //include field filters in search querystring parameter$url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&paging[page_size]=1000&search=' . $search_json;
JavaScript
123456789101112131415var search = {        field_filters : [            {                key: '2.6',                value: 'Harris',                operator: 'is'            }        ]    }; //convert to a JSON string and url encode it so the JSON formatting persistssearch = encodeURI(JSON.stringify(search)); //add search to urlurl += '&search=' + search;
The JSON string created by the code above and used in the querystring will look like the following before it is URL encoded:
1{"field_filters":[{"key":"1.6","operator":"is","value":"Draven"}]}
Retrieve entries using field filters (multiple conditions)
The example below retrieves entries where the last name field (1.6) is 「Draven」 and the first name field (1.3) is not 「Eric」. If all conditions specified need to be met, the 「mode」 is set to 「all」 (the keyword 「AND」 is used in the database query). If all conditions are not necessary, set the 「mode」 to 「any」 (the keyword 「OR」 is used in the database query). The default mode is 「all」 so you do not need to include it when all conditions are required. To see more information about using field filters, check out the Field Filters section in the REST API v1 article.
PHP
1234567891011121314151617$field_filters = array (                     'mode' => 'any',                     array(                         'key'      => '1.6',                         'operator' => 'is',                         'value'    => 'Draven'                     ),                     array(                         'key'      => '1.3',                         'operator' => 'isnot',                         'value'    => 'Eric'                     ),                 );$search['field_filters'] = $field_filters;$search_json = urlencode( json_encode( $search ) ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&paging[page_size]=1000&search=' . $search_json;
JavaScript
1234567891011121314151617181920var search = {        field_filters : [            {                key: '2.6',                value: 'Harris',                operator: 'is'            },                        {                key: '2.3',                value:'Xander',                operator: 'is'            }        ]    }; //convert to a JSON string and url encode it so the JSON formatting persistssearch = encodeURI(JSON.stringify(search)); //add search to urlurl += '&search=' + search;
The JSON string created by the code above and used in the querystring will look like the following before it is URL encoded:
1{"field_filters":{"mode":"any","0":{"key":"1.6","operator":"is","value":"Draven"},"1":{"key":"1.3","operator":"isnot","value":"Eric"}}}
Retrieve entries using field filters (contains condition)
The example below retrieves entries that have the text 「er」 as part of the last name field (id 1.6).
PHP
1234567891011$field_filters = array (                     array(                         'key'      => '1.6',                         'operator' => 'contains',                         'value'    => 'er'                     ),                 );$search['field_filters'] = $field_filters;$search_json = urlencode( json_encode( $search ) ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&paging[page_size]=1000&search=' . $search_json;
JavaScript
123456789101112131415var search = {        field_filters : [            {                key: '2.6',                operator: 'contains',                value: 'er'            }        ]    }; //convert to a JSON string and url encode it so the JSON formatting persistssearch = encodeURI(JSON.stringify(search)); //add search to urlurl += '&search=' + search;
The JSON string created by the code above and used in the querystring will look like the following before it is URL encoded:
1{"field_filters":[{"key":"1.6","operator":"contains","value":"er"}]}
Retrieve entries using search criteria and field filters
The example below retrieves entries that have the text 「Test」 as part of the last name field (id 1.6) and have been created since 2016-10-10
PHP
12345678910111213$field_filters = array (            array(                'key'       => '1.6',                'operator'  => 'contains',                'value'     => 'Test'            ),        );        $search = [];        $search['field_filters'] = $field_filters;        $search['start_date'] = '2016-10-10';        $search_json = urlencode( json_encode( $search ) );         $url .= '&search=' . $search_json;
JavaScript
12345678910111213141516var search = {        field_filters : [            {                key: '1.6',                operator: 'contains',                value: 'Test'            }        ],        start_date : '2016-10-10'}; //convert to a JSON string and url encode it so the JSON formatting persistssearch = encodeURI(JSON.stringify(search)); //add search to urlurl += '&search=' + search;
The JSON string created by the code above and used in the querystring will look like the following before it is URL encoded:
1{"field_filters":[{"key":"1.6","operator":"contains","value":"Test"}],"start_date":"2016-10-10"}
Retrieve entries that have been read
PHP
1234567891011$field_filters = array (                     array(                         'key'      => 'is_read',                         'operator' => 'is',                         'value'    => 1                     ),                 );$search['field_filters'] = $field_filters;$search_json = urlencode( json_encode( $search ) ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&paging[page_size]=1000&search=' . $search_json;
JavaScript
12345678910111213141516var search = {        field_filters : [            {                key: 'is_read',                operator: 'is',                value: 1             }        ]    }; //convert to a JSON string and url encode it so the JSON formatting persistssearch = encodeURI(JSON.stringify(search)); //add search to urlurl += '&search=' + search;
Retrieve all entries with paging
The example below is a basic use of paging with previous/next links. The page size is set to 5 and the offset is used to control which results are displayed as you navigate through the pages. To see more information about paging, see the Paging section of the REST API v1 article.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112public static function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;}$base_url = 'http://localhost/wpdev/gravityformsapi/';$api_key = '9419b823a1';$private_key = '4d7640ad3ffe2ec';$method  = 'GET';$route = 'entries';$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, $method, $route, $expires );$sig = self::calculate_signature( $string_to_sign, $private_key ); $page_size = 5;$offset = 0;if ( isset( $_GET['paging']['offset'] ) ){    $offset = $_GET['paging']['offset'];} $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&paging[$page_size]=' . $page_size . '&paging[offset]=' . $offset; $response = wp_remote_request( $url, array('method' => 'GET' ) ); if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    echo 'There was an error attempting to access the API.';    die();} $body_json = wp_remote_retrieve_body( $response );//results are in the "body" and are json encoded, decode them and put into an array$body = json_decode( $body_json, true ); $data            = $body['response'];$status_code     = $body['status'];$total           = 0;$total_retrieved = 0; if ( $status_code <= 202 ){    //entries retrieved successfully    $entries         = $data['entries'];    $status          = $status_code;    $total           = $data['total_count'];    $total_retrieved = count( $entries );}else {    //entry retrieval failed, get error information    $error_code    = $data['code'];    $error_message = $data['message'];    $error_data    = isset( $data['data'] ) ? $data['data'] : '';    $status        = $status_code . ' - ' . $error_code . ' ' . $error_message . ' ' . $error_data;}//display results in a simple page?>

    

Results

    

Status Code:

    

Total Count:

    

Total Retrieved:

    

JSON Response:

    
    

         0 ) {            echo '

';            foreach ( $entries as $entry ){                echo '

';            }            echo '

Form ID Entry ID Date Created
' . $entry['form_id'] . ' ' . $entry['id'] . ' ' . $entry['date_created'] . '

';        }         if ( $total > $total_retrieved ){            //paging in effect            $query_string = $_SERVER['QUERY_STRING'];            parse_str( $query_string, $params );            $paging_link = '';            if ( $total_retrieved == $page_size ){                //see if previous link needs to be built                $page_offset = isset( $params['paging']['offset'] ) ? $params['paging']['offset'] : 0;                if ( $page_offset <> 0 ) {                    $previous_page_offset = $params['paging']['offset'] - $page_size;                    if ( $previous_page_offset < 0 ){                        $previous_page_offset = 0;                    }                    $params['paging']['offset'] = $previous_page_offset;                    $page_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query( $params );                    $paging_link = 'Previous     ';                }                $params['paging']['offset'] = $page_offset + $page_size;                $page_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query( $params );                $paging_link .= 'Next';            }            else {                $page_offset = $params['paging']['offset'] - $page_size;                if ( $page_offset < 0 ){                    $page_offset = 0;                }                $params['paging']['offset'] = $page_offset;                $page_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query( $params );                $paging_link = 'Previous';            }             echo $paging_link;        }        ?>    


JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041
Retrieve a single entry
This example may be viewed in the REST API v1 article.
Retrieve specific fields for a single entry
This example may be viewed in the REST API v1 article.
Retrieve specific fields for multiple entries
This example may be viewed in the REST API v1 article.
Create Entries
Create Entries
This example may be viewed in the REST API v1 article.
Create Entry for a Specific Form
This example may be viewed in the REST API v1 article.
Update Entries
Update Single Entry (Create Entry Array Manually)
The example below updates entry id 157.
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273public static function calculate_signature( $string, $private_key ) {  $hash = hash_hmac( 'sha1', $string, $private_key, true );  $sig = rawurlencode( base64_encode( $hash ) );  return $sig;} $base_url = 'http://localhost/wpdev/gravityformsapi/';$api_key = 'your_api_key';$private_key = 'your_private_key';$method = 'PUT';$route = 'entries/157';$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, $method, $route, $expires );$sig = self::calculate_signature( $string_to_sign, $private_key ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; $entry = array(             'form_id'      => '28',             'date_created' => '2015-06-15 22:43:23',             'is_starred'   => 0,             'is_read'      => 1,             'ip'           => '::1',             'source_url'   => 'http://localhost/wpdev/?gf_page=preview&id=28',             'currency'     => 'USD',             'created_by'   => 1,             'user_agent'   => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0',             'status'       => 'active',             '1.3'          => 'Eric',             '1.6'          => 'Draven',             '2'            => 'brandonlee',             '3'            => 'The Crows',     ); $entry_json = json_encode( $entry ); $response = wp_remote_request( $url, array( 'method' => $method, 'body' => $entry_json ) ); if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    echo 'There was an error attempting to access the API.';    die();} $body_json = wp_remote_retrieve_body( $response );//results are in the "body" and are json encoded, decode them and put into an array$body = json_decode( $body_json, true ); $data        = $body['response'];$status_code = $body['status']; if ( $status_code <= 202 ){    //entries retrieved successfully    $status  = $status_code;}else {    //entry update failed, get error information    $error_code    = $data['code'];    $error_message = $data['message'];    $error_data    = isset( $data['data'] ) ? $data['data'] : '';    $status        = $status_code . ' - ' . $error_code . ' ' . $error_message . ' ' . $error_data;}//display results in a simple page?>

    

Results

    

Status Code:

    

JSON Response:


JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
Update Single Entry (Create Entry Array Using Existing Database Record)
This example may be viewed in the REST API v1 article.
Update Entries (Create Entries Array Manually)
This example may be viewed in the REST API v1 article.
Update Entries (Create Entries Array Using Existing Database Records)
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576public static function calculate_signature( $string, $private_key ) {  $hash = hash_hmac( 'sha1', $string, $private_key, true );  $sig = rawurlencode( base64_encode( $hash ) );  return $sig;} $base_url = 'http://localhost/wpdev/gravityformsapi/';$api_key = 'your_api_key';$private_key = 'your_private_key';$method = 'PUT';$route = 'entries';$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, $method, $route, $expires );$sig = self::calculate_signature( $string_to_sign, $private_key ); $url = $base_url . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; //get entry object for id 156 and modify$entry1 = GFAPI::get_entry( 156 );$entry1['is_starred'] = 1;$entry1['3'] = 'Newt';//add entry to entries array$entries[] = $entry1; //get entry object for id 157 and modify$entry2 = GFAPI::get_entry( 157 );$entry2['2'] = 'eric draven';$entry2['is_read'] = 0;//add entry to entries array$entries[] = $entry2; //json encode array$entry_json = json_encode( $entries ); $response = wp_remote_request( $url, array( 'method' => $method, 'body' => $entry_json ) ); if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    echo 'There was an error attempting to access the API.';    die();} $body_json = wp_remote_retrieve_body( $response );//results are in the "body" and are json encoded, decode them and put into an array$body = json_decode( $body_json, true ); $data        = $body['response'];$status_code = $body['status']; if ( $status_code <= 202 ){    //entries retrieved successfully    $status  = $status_code;}else {    //entry update failed, get error information, error could just be a string    if ( is_array( $data )){        $error_code    = $data['code'];        $error_message = $data['message'];        $error_data    = isset( $data['data'] ) ? $data['data'] : '';        $status        = $status_code . ' - ' . $error_code . ' ' . $error_message . ' ' . $error_data;    }    else{        $status = $data;    }}//display results in a simple page?>

    

Results

    

Status Code:

    

JSON Response:


JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
Delete Entries
Delete Multiple Entries
This example may be viewed in the REST API v1 article.
Forms
Retrieve Forms
Retrieve all active forms
This example retrieves all active forms and displays them in a list.
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} //set API keys$api_key = 'your_api_key';$private_key = 'your_private_key'; //set route$route = 'forms'; //creating request URL$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'GET', $route, $expires );$sig = self::calculate_signature( $string_to_sign, $private_key );$url = 'http://localhost/wpdev/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; //retrieve data$response = wp_remote_request( $url, array( 'method' => 'GET' ) );if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    die( 'There was an error attempting to access the API.' );} //result is in the response "body" and is json encoded.$body = json_decode( wp_remote_retrieve_body( $response ), true ); if( $body['status'] > 202 ){    die( "Could not retrieve forms." );} //forms retrieved successfully$forms = $body['response']; //display results in a simple page?>

    

Forms

    

         Form ID Form Title Entry Count

';            foreach ( $forms as $form ) {                echo '

' . $form['id'] . ' ' . $form['title'] . ' ' . $form['entries'] . '

';            }            echo '

';        }        ?>    

    
    

JSON Response:


JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142
Retrieve a single form
This example retrieves a single form and displays the details, along with field information.
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} //set API keys$api_key = 'your_api_key';$private_key = 'your_private_key'; //set route$route = 'forms/67'; //creating request URL$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'GET', $route, $expires );$sig = calculate_signature( $string_to_sign, $private_key );$url = 'http://localhost/wp/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; //retrieve data$response = wp_remote_request( $url, array( 'method' => 'GET' ) );if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    die( 'There was an error attempting to access the API.' );} //result is in the response "body" and is json encoded.$body = json_decode( wp_remote_retrieve_body( $response ), true ); if( $body['status'] > 202 ){    die( "Could not retrieve forms." );} //forms retrieved successfully$form = $body['response']; //display results in a simple page?>

    

Forms

    

         Form ID Form Title Field Count

';            //foreach ( $forms as $form ) {                $fields = $form['fields'];                echo '

' . $form['id'] . ' ' . $form['title'] . ' ' . count( $fields ) . '

';                if ( $fields ){                    echo '

';                    foreach ( $fields as $field ){                        echo '

';                    }                    echo '

Field ID Field Label Field Type
' . $field['id'] . ' ' . GFCommon::get_label( $field ) . ' ' . $field['type'] . '

';                }                echo '

 

';            //}            echo '

';        }        ?>    

    
    

JSON Response:


JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
Retrieve multiple forms
This example retrieves multiple forms and displays the details, along with field information. If a form cannot be found, false is returned instead of a form object.
PHP
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} //set API keys$api_key = 'your_api_key';$private_key = 'your_private_key'; //set route$route = 'forms/67;68;1'; //creating request URL$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'GET', $route, $expires );$sig = calculate_signature( $string_to_sign, $private_key );$url = 'http://localhost/wpdev/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; //retrieve data$response = wp_remote_request( $url, array( 'method' => 'GET' ) );if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    die( 'There was an error attempting to access the API.' );} //result is in the response "body" and is json encoded.$body = json_decode( wp_remote_retrieve_body( $response ), true ); if( $body['status'] > 202 ){    die( "Could not retrieve forms." );} //forms retrieved successfully$forms = $body['response']; //display results in a simple page?>

    

Forms

    

         Form ID Form Title Field Count

';            foreach ( $forms as $form_id => $form ) {                if ( ! $form ){                    //if a form is not found, false is returned                    echo '

Form ID ' . $form_id . ' could not be found.

';                }                else{                    $fields = $form['fields'];                    echo '

' . $form['id'] . ' ' . $form['title'] . ' ' . count( $fields ) . '

';                    if ( $fields ){                        //display basic field info                        echo '

';                        foreach ( $fields as $field ){                            echo '

';                        }                        echo '

Field ID Field Label Field Type
' . $field['id'] . ' ' . GFCommon::get_label( $field ) . ' ' . $field['type'] . '

';                    }                }                echo '

 

';            }            echo '

';        }        ?>    

    
    

JSON Response:


JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
Insert Forms
Insert a single form
The example below inserts a new form.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} //set API keys$api_key = 'your_api_key';$private_key = 'your_private_key'; //set route$route = 'forms'; //creating request URL$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'POST', $route, $expires );$sig = calculate_signature( $string_to_sign, $private_key );$url = 'http://localhost/wpdev/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; $form = array(        array(            'title'          => 'API Generated Form',            'description'    => 'This is the description for the form generated by the API',            'labelPlacement' => 'top_label',            'button'         => array(                            'type' => 'text'            ),            'confirmations'  => array(                        array(                            'id' => 0,                            'name' => 'Default Confirmation',                            'type' => 'message',                            'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                            'isDefault' => true,                        ),            ),            'fields'     => array(                         array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                         )                    ),        ),); //json encode array$form_json = json_encode( $form ); //retrieve data$response = wp_remote_request( $url, array( 'method' => 'POST', 'body' => $form_json ) );if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    die( 'There was an error attempting to access the API.' );} //result is in the response "body" and is json encoded.$body = json_decode( wp_remote_retrieve_body( $response ), true ); if( $body['status'] > 202 ){    $error = $body['response'];     //form insert failed, get error information    $error_code     = $error['code'];    $error_message  = $error['message'];    $error_data     = isset( $error['data'] ) ? $error['data'] : '';    $status     = "Code: {$error_code}. Message: {$error_message}. Data: {$error_data}.";    die( "Could not post forms. {$status}" );} $form_id = $body['response'][0];echo 'The following form id was created: ' . $form_id . '
';
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
Insert form with the confirmation set to redirect
The example below shows how to build the form array to have the confirmation as a redirect.
PHP
1234567891011121314151617181920212223242526$form = array(            array(                'title'      => 'API Generated Form With Redirect Confirmation',                'description'    => 'This is the description for the form generated by the API',                'labelPlacement' => 'top_label',                'button'         => array(                    'type' => 'text'                ),                'confirmations'  => array(                    array(                        'id' => 0,                        'name' => 'Default Confirmation',                        'type' => 'redirect',                        'url' => 'http://www.rocketgenius.com',                        'isDefault' => true,                    ),                ),                'fields'         => array(                    array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                    )                ),            ),        );
JavaScript
1234567891011121314var form = {    title       : 'API Generated Form With Redirect Confirmation',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button          : {type : 'text'},    confirmations   : [        {id : 0, name : 'Default Confirmation', type : 'redirect', url : 'http://www.rocketgenius.com', isDefault : true},        {id : 1, name : 'Confirmation 2', type : 'message', message : 'Thanks for contacting us! We will get in touch with you shortly.', isDefault : false}    ],    fields          : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'}    ]};
Insert form with the confirmation set to page
The example below shows how to build the form array to have the confirmation as a page.
PHP
1234567891011121314151617181920212223242526$form = array(        array(            'title'          => 'API Generated Form with Page Confirmation',            'description'    => 'This is the description for the form generated by the API',            'labelPlacement' => 'top_label',            'button'         => array(                'type' => 'text'            ),            'confirmations'  => array(                          array(                        'id' => 0,                        'name' => 'Default Confirmation',                        'type' => 'page',                        'pageId' => 500,                        'isDefault' => true,                          ),            ),            'fields'  => array(                    array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                    )                ),            ),        );
JavaScript
12345678910111213var form = {    title       : 'API Generated Form with Page Confirmation',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button      : {type : 'text'},    confirmations   : [        {id : 0, name : 'Default Confirmation', type : 'page', pageId : 2, isDefault : true}    ],    fields      : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'}    ]};
Insert form with a conditional confirmation
The example below shows how to build the form array to have a conditional confirmation.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354$form = array(    array(        'title'      => 'API Generated Test Confirmations with new array 3',        'description'    => 'This is the description for the form generated by the API',        'labelPlacement' => 'top_label',        'button'     => array(                          'type' => 'text'                            ),        'confirmations'  => array(                          array(                        'id'        => 0,                        'name'      => 'Default Confirmation',                        'type'      => 'message',                        'message'   => 'Thanks for contacting us! We will get in touch with you shortly.',                        'isDefault' => true,                          ),                          array(                        'id'        => 1,                        'name'      => 'My Conditional',                        'type'      => 'message',                        'message'   => 'This is my conditional confirmation that will be used if the text is test.',                        'isDefault' => false,                        'conditionalLogic' => array(                                    'actionType' => 'show',                                'logicType'  => 'any',                                'rules'      => array(                                          array(                                            'fieldId'  => 1,                                            'operator' => 'is',                                            'value'    => 'test',                                          ),                                          array(                                            'fieldId'  => 1,                                            'operator' => 'is',                                            'value'    => 'TEST',                                          ),                                          array(                                            'fieldId'  => 1,                                            'operator' => 'is',                                            'value'    => 'Test',                                          ),                                                                                ),                                 ),                        )        ),        'fields' => array(                  array(                'id' => '1',                'label' => 'My Text',                'type'  => 'text'                 )        ),    ),);
JavaScript
12345678910111213141516171819202122var form = {    title       : 'API Generated Test Confirmations Conditionals',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button      : {type : 'text'},    confirmations   : [        {id : '0', name : 'Default Confirmation', type : 'message', message : 'Thanks for contacting us! We will get in touch with you shortly.', isDefault : true},        {id : '1', name : 'My Conditional', type : 'message', message : 'This is my conditional confirmation that will be used if the text is test.', isDefault : false,            conditionalLogic : {actionType : 'show', logicType : 'any',                rules : [                    {fieldId : '1', operator : 'is', value : 'test'},                    {fieldId : '1', operator : 'is', value : 'TEST'},                    {fieldId : '1', operator : 'is', value : 'Test'}                ]            }        }    ],    fields      : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'}    ]};
Insert form with notifications sent to a specific email address
The example below shows how to build the form array to have notifications which are sent to a specific email address. Please see the article titled Notifications Object for more details about what may be included when building the notification array.
PHP
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950$form = array(            array(                'title'          => 'API Generated Form With Notification Sent to Specific Email Address',                'description'    => 'This is the description for the form generated by the API',                'labelPlacement' => 'top_label',                'button'         => array(                    'type' => 'text'                ),                'notifications' => array(                    array(                        'id'        => uniqid( '0' ),                        'name'      => 'Admin Notification',                        'to'        => '{admin_email}',                        'toType'    => 'email',                        'event'     => 'form_submission',                        'subject'   => 'New submission from {form_title}',                        'message'   => '{all_fields}',                        'from'      => '{admin_email}',                        'fromName'  => 'Administrator'                    ),                    array(                        'id'        => uniqid( '1' ),                        'name'      => 'Admin Notification 2',                        'to'        => '{admin_email}',                        'toType'    => 'email',                        'event'     => 'form_submission',                        'subject'   => 'New submission from {form_title}',                        'message'   => '{all_fields}',                        'from'      => '{admin_email}',                        'isActive'  => false,                    ),                ),                'confirmations'  => array(                    array(                        'id' => 0,                        'name' => 'Default Confirmation',                        'type' => 'message',                        'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                        'isDefault' => true,                    ),                ),                'fields'         => array(                    array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                    )                ),            ),        );
JavaScript
1234567891011121314151617var form = {    title       : 'API Generated Form With Notification Sent to Specific Email Address',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button      : {type : 'text'},    confirmations   : [        {id : '0', name : 'Default Confirmation', type : 'message', message : 'Thanks for contacting us! We will get in touch with you shortly.', isDefault : true}    ],    fields      : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'}    ],    notifications : [        {id : Math.floor(Math.random() * 1000), name : 'Admin Notification 1', to : '{admin_email}', toType : 'email', event : 'form_submission', subject : 'New submission from {form_title}', message : '{all_fields}', from : '{admin_email}', fromName : 'Administrator'},        {id : Math.floor(Math.random() * 1000), name : 'Admin Notification 2', to : '{admin_email}', toType : 'email', event : 'form_submission', subject : 'New submission from {form_title}', message : '{all_fields}', from : '{admin_email}', isActive : false}    ]};
Insert form with notification set to use an email field
The example below shows how to build the form array to have a notification which is sent to a specific email address field. Please see the article titled Notifications Object for more details about what may be included when building the notification array.
PHP
1234567891011121314151617181920212223242526272829303132333435363738394041424344$form = array(            array(                'title'          => 'API Generated Form With Notification Set to Field',                'description'    => 'This is the description for the form generated by the API',                'labelPlacement' => 'top_label',                'button'         => array(                    'type' => 'text'                ),                'notifications' => array(                    array(                        'id'        => uniqid( '0' ),                        'name'      => 'Admin Notification',                        'to'        => '2',                        'toType'    => 'field',                        'event'     => 'form_submission',                        'subject'   => 'New submission from {form_title}',                        'message'   => '{all_fields}',                        'from'      => '{admin_email}',                        'fromName'  => 'Administrator'                    ),                ),                'confirmations'  => array(                    array(                        'id' => uniqid(),                        'name' => 'Default Confirmation',                        'type' => 'message',                        'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                        'isDefault' => true,                    ),                ),                'fields'         => array(                    array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                    ),                    array(                        'id' => '2',                        'label' => 'Email',                        'type'  => 'email'                    ),                ),            ),        );
JavaScript
1234567891011121314151617var form = {    title       : 'API Generated Form With Notification Sent to Specific Email Address',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button      : {type : 'text'},    confirmations   : [        {id : '0', name : 'Default Confirmation', type : 'message', message : 'Thanks for contacting us! We will get in touch with you shortly.', isDefault : true}    ],    fields      : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'},        {id : '3', label : 'Email', type : 'email'}    ],    notifications : [        {id : Math.floor(Math.random() * 1000), name : 'Admin Notification 1', to : '3', toType : 'field', event : 'form_submission', subject : 'New submission from {form_title}', message : '{all_fields}', from : '{admin_email}', fromName : 'Administrator'}    ]};
Insert form with notification set to use routing
The example below shows how to build the form array to have a notification which is sent using routing rules. Please see the article titled Notifications Object for more details about what may be included when building the notification array.
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758$form = array(            array(                'title'          => 'API Generated Test Confirmations with new array 3',                'description'    => 'This is the description for the form generated by the API',                'labelPlacement' => 'top_label',                'button'         => array(                    'type' => 'text'                ),                'notifications' => array(                    array(                        'id'        => uniqid( '0' ),                        'name'      => 'Admin Notification',                        'toType'    => 'routing',                        'event'     => 'form_submission',                        'subject'   => 'New submission from {form_title}',                        'message'   => '{all_fields}',                        'from'      => '{admin_email}',                        'fromName'  => 'Administrator',                        'isActive'  => true,                        'routing'   => array(                                            array(                                                'fieldId'  => '1',                                                'operator' => 'is',                                                'value'    => 'test',                                                'email'    => '{admin_email}',                                            ),                                            array(                                                'fieldId'  => '2',                                                'operator' => 'is',                                                'value'    => '[email protected]',                                                'email'    => '{admin_email}',                                            )                        ),                    ),                ),                'confirmations'  => array(                    array(                        'id' => uniqid(),                        'name' => 'Default Confirmation',                        'type' => 'message',                        'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                        'isDefault' => true,                    ),                ),                'fields'         => array(                    array(                        'id' => '1',                        'label' => 'My Text',                        'type'  => 'text'                    ),                    array(                        'id' => '2',                        'label' => 'Email',                        'type'  => 'email'                    ),                ),            ),        );
JavaScript
12345678910111213141516171819202122var form = {    title       : 'API Generated Form With Notification Sent to Specific Email Address',    description : 'This is the description for the form generated by the API',    labelPlacement  : 'top_label',    button      : {type : 'text'},    confirmations   : [        {id : '0', name : 'Default Confirmation', type : 'message', message : 'Thanks for contacting us! We will get in touch with you shortly.', isDefault : true}    ],    fields      : [        {id : '1', label : 'My Text', type : 'text'},        {id : '2', label : 'More Text', type : 'text'},        {id : '3', label : 'Email', type : 'email'}    ],    notifications : [        {id : Math.floor(Math.random() * 1000), name : 'Admin Notification', toType : 'routing', event : 'form_submission', subject : 'New submission from {form_title}', message : '{all_fields}', from : '{admin_email}', fromName : 'Administrator', isActive : true,        routing : [            {fieldId : '1', operator : 'is', value : 'test', email : '{admin_email}'},            {fieldId : '2', operator : 'is', value : '[email protected]', email : '{admin_email}'}        ]        }    ]};
Insert multiple forms
The example below inserts two new forms and displays the ids of the forms inserted.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103function calculate_signature( $string, $private_key ) {    $hash = hash_hmac( 'sha1', $string, $private_key, true );    $sig = rawurlencode( base64_encode( $hash ) );    return $sig;} //set API keys$api_key = 'your_api_key';$private_key = 'your_private_key'; //set route$route = 'forms'; //creating request URL$expires = strtotime( '+60 mins' );$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'POST', $route, $expires );$sig = calculate_signature( $string_to_sign, $private_key );$url = 'http://localhost/wpdev/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires; $form = array(    array(        'title'          => 'API Generated Form 1',        'description'    => 'This is the description for the form generated by the API',        'labelPlacement' => 'top_label',        'button'         => array(                                'type' => 'text'        ),        'confirmations'  => array(            array(                'id' => 0,                'name' => 'Default Confirmation',                'type' => 'message',                'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                'isDefault' => true,            ),        ),        'fields'         => array(            array(                'id' => '1',                'label' => 'My Text',                'type'  => 'text'            )        ),    ),    array(        'title'          => 'API Generated Form 2',        'description'    => 'This is the description for the form generated by the API',        'labelPlacement' => 'top_label',        'button'         => array(            'type' => 'text'        ),        'confirmations'  => array(            array(                'id' => 0,                'name' => 'Default Confirmation',                'type' => 'message',                'message' => 'Thanks for contacting us! We will get in touch with you shortly.',                'isDefault' => true,            ),        ),        'fields'         => array(            array(                'id' => '1',                'label' => 'My Text',                'type'  => 'text'            )        ),    ),); //json encode array$form_json = json_encode( $form ); //retrieve data$response = wp_remote_request( $url, array( 'method' => 'POST', 'body' => $form_json ) );if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){    //http request failed    die( 'There was an error attempting to access the API.' );} //result is in the response "body" and is json encoded.$body = json_decode( wp_remote_retrieve_body( $response ), true ); //echo $response['body'];  if( $body['status'] > 202 ){    $error = $body['response'];     //form insert failed, get error information    $error_code     = $error['code'];    $error_message  = $error['message'];    $error_data     = isset( $error['data'] ) ? $error['data'] : '';    $status     = "Code: {$error_code}. Message: {$error_message}. Data: {$error_data}.";    die( "Could not post forms. {$status}" );} $form_ids = $body['response'];$form_ids_created = '';foreach ( $form_ids as $form_id ){    $form_ids_created .= $form_id . '
';}echo 'The following form ids were created: ' . $form_ids_created . '
';
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
Update Forms
Update multiple forms
This example may be viewed in the REST API v1 article.
Delete Forms
This example may be viewed in the REST API v1 article.
Form Submissions
Complex Fields
Submit a list field that has a single column
This example shows how to create the input_values array for a list field (field 1) that has a single column. Each value in the array will be a separate row.
123456$values = array(            'input_values' => array(                                'input_1' => array('row1','row2'),                                'input_2' => 'test'                  )         );
Submit a list field that has multiple columns
This example shows how to create the input_values array for a list field (field 1) that has three columns. Each value in the array will fill up the columns for a row until starting on the columns for the next row. Use 」 if there is no value for a column in a particular row. The value 『test』 in the example starts a fourth row.
12345$values = array(            'input_values' => array(                                'input_1' => array('row1col1','row1col2','row1col3','row2col1','row2col2','row3col3','row3col1','row3col2','row3col3','test'),                  )        );
Submit a Multi-Select Field
This example shows how to create the input_values array for a multi-select field (field 1).
12345$values = array(            'input_values' => array(                                'input_1' => array('First Choice','Third Choice'),                  )        );
Pricing Fields
Single Product Field
This example shows how to create the input_values array for a Single Product Pricing field (field 1).
12345678$values = array(            'input_values' => array(                                'input_1_1' => 'test product', //product name                                'input_1_2' => '$5.00', //product price with formatting                                'input_1_3' => 1, //product quantity                               )          );
Single Product Field With Option
This examples shows how to create the input_values array for a product with an associated option (field id 2). The option needs to be in the format option name, pipe symbol, option price. This is the format whether the option is a drop down, check box, or radio button. When using check boxes, which allow multiple selections, you will need to reference the input fields a little differently. See the next example for this.
123456789$values = array(            'input_values' => array(                                'input_1_1' => 'test product', //product name                                'input_1_2' => '$5.00', //product price with formatting                                'input_1_3' => 1, //product quantity                                'input_2'   => 'Second Option|4' //option name|option price                               )          );
Option Field as a Checkbox
This example shows how to create the input_values array when the option associated to a product is a checkbox.
123456789$values = array(            'input_values' => array(                                'input_1_1' => 'test product', //product name                                'input_1_2' => '$5.00', //product price with formatting                                'input_1_3' => 1, //product quantity                                'input_2_1' => 'First Option|2', //option name|option price                                'input_2_3' => 'Third Option|6'                              )          );

發表回覆

您的電子郵箱地址不會被公開。 必填項已用 * 標註