gform_zapier_request_body

Description

Allows the request body sent to Zapier to be filtered.

Usage

The following would apply to all forms:

add_filter('gform_zapier_request_body', 'your_function_name', 10, 4);

To target a specific form, append the form id to the hook name.
Format: gform_zapier_request_body_FORMID

add_filter('gform_zapier_request_body_1', 'your_function_name', 10, 4);

Parameters

NameTypeNote
$bodyarrayAn associative array containing the request body that will be sent to Zapier.
$feedFeed ObjectThe feed object currently being processed.
$entryEntry ObjectThe entry object currently being processed.
$formForm ObjectThe form object currently being processed.

Examples

1. Change Date format

add_filter('gform_zapier_request_body', 'change_date_format', 10, 4);
      function change_date_format( $body, $feed, $entry, $form ){
      		$body['Entry Date'] = gmdate('Y-m-d', strtotime( $entry['date_created'] ) );
      		return $body;
      }

2. Send Score for Survey fields

add_filter( 'gform_zapier_request_body', 'zapier_single_score_export', 10, 4 );
function zapier_single_score_export( $body, $feed, $entry, $form ) {
	$survey_fields = GFAPI::get_fields_by_type( $form, array( 'survey' ) );
	foreach ( $survey_fields as $field ) {
		$body_key          = GF_Zapier::get_body_key( $body, 'Survey Score: ' . $field->label );
		$body[ $body_key ] = gf_survey()->get_field_score( $field, $entry );
	}

	return $body;
}

3. Adjust GMT Entry Date to Local Time

Gravity Forms stores the date_created in GMT. Use this snippet to adjust the date/time to the local timezone based on the WordPress Timezone setting.

add_filter('gform_zapier_request_body', function( $body, $feed, $entry, $form ) {
    $body['Entry Date'] = GFCommon::format_date( $entry['date_created'], false, 'Y-m-d H:i:s', false );
    return $body;
}, 10, 4 );

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in the Gravity Forms Zapier Add-On v3.1.1.

Source Code

This filter is located in GF_Zapier::get_body() method in zapier.php.