gravityflow_webhook_args

The gravityflow_webhook_args filter allow the webhook to be modified before it's sent.

Example 1 - Processing request as per a specific Step ID.

add_filter( 'gravityflow_webhook_args', 'sh_filter_gravityflow_webhook_args', 10, 3 ); 
function sh_filter_gravityflow_webhook_args( $args, $entry, $current_step ) {  
	$step_id = $current_step->get_id(); 
	// only processing for a particular step, exampe step id 87
	if ( $step_id == 87 ) {
		// Add process specific to the selected step here.
	}
	return $args;
}

Example 2 - Modify arguments based on method (get/post/etc)

add_filter( 'gravityflow_webhook_args', 'sh_filter_gravityflow_webhook_args', 10, 3 );
function sh_filter_gravityflow_webhook_args( $args, $entry, $current_step ) {
	// POST only the value of field 2 with a custom key
	if ( $args['method'] == 'POST' ) {
		$args['body'] = array( 'my_value' => $entry['2'] );
	}
	return $args;
}

Example 3 - Add basic authentication using username and password

add_filter( 'gravityflow_webhook_args', 'sh_filter_gravityflow_webhook_args', 10, 3 );
function sh_filter_gravityflow_webhook_args( $args, $entry, $current_step ) {
	$args['headers'] = array(
            'Authorization' => 'Basic ' . base64_encode( YOUR_USERNAME . ':' . YOUR_PASSWORD )
       );

    return $args;
}

Example 4 - Checking URL to determine whether additional webhook arguments are required.

add_filter( 'gravityflow_webhook_args', 'sh_filter_gravityflow_webhook_args', 10, 3 );
function sh_filter_gravityflow_webhook_args( $args, $entry, $current_step ) {
  if ($current_step->url == "test.salesforce.com") {
    // modifying the authentication headers conditionally
    $args['headers'] = array(
      'Authorization' => 'Basic ' . base64_encode( YOUR_USERNAME . ':' . YOUR_PASSWORD )
    );
  }
  return $args;
}

Example 5 - Add custom headers based on step settings

By default, when you select the outgoing webhook format to be FORM, the headers are ignored. This snippet will allow you to override/customize based on step settings to include extra headers.

add_filter( 'gravityflow_webhook_args', 'jo_filter_gravityflow_webhook_args', 10, 3 );
function jo_filter_gravityflow_webhook_args( $args, $entry, $current_step ) {
	if ( $current_step->get_id() == 128 && $current_step->get_setting('format') == 'form' ) {
		//Apply request headers based on step setting defined header key/values
		$headers = gravity_flow()->get_generic_map_fields( $current_step->get_feed_meta(), 'requestHeaders', $current_step->get_form(), $entry );
		// Remove request headers with undefined name.
		unset( $headers[ null ] );
		//To customize headers with separate logic based on step settings header key/values
		//$headers = $current_step->get_setting('requestHeaders');
		$args['headers'] = $headers;

	}
	return $args;
}

Placement

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