Filter uncanny-automator

automator_send_webhook_remote_args

Filters the arguments before sending a webhook, allowing customization of the request type and data.

add_filter( 'automator_send_webhook_remote_args', $callback, 10, 3 );

Description

Fires before a webhook is sent to prepare the remote request arguments. Developers can modify the request method, body, and timeout. This filter is crucial for customizing webhook payloads and ensuring compatibility with various API endpoints before the request is executed.


Usage

add_filter( 'automator_send_webhook_remote_args', 'your_function_name', 10, 3 );

Parameters

$request_type (mixed)
This parameter contains the HTTP request method (e.g., POST, GET) that will be used to send the webhook.
$data (mixed)
This parameter specifies the HTTP request method to be used for the webhook.
$this (mixed)
This parameter contains the data being sent in the webhook request.

Return Value

The filtered value.


Examples

// Modify the arguments passed to the WordPress HTTP API for sending webhooks.
// This example adds a custom header to the webhook request.
add_filter(
	'automator_send_webhook_remote_args',
	function ( $args, $data, $webhook_instance ) {
		// Ensure the 'headers' key exists in the $args array.
		if ( ! isset( $args['headers'] ) ) {
			$args['headers'] = array();
		}

		// Add a custom header to the webhook request.
		// This could be an API key, authentication token, or any other required header.
		$args['headers']['X-My-Custom-Header'] = 'MySecretValue';

		// You could also conditionally modify other arguments based on $data or $webhook_instance.
		// For example, change the timeout if the data indicates a large payload:
		// if ( isset( $data['payload_size'] ) && $data['payload_size'] > 1024 ) {
		//     $args['timeout'] = '60';
		// }

		return $args;
	},
	10, // Default priority
	3   // Number of arguments accepted by the filter callback
);

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/core/lib/recipe-parts/trait-webhooks.php:123

$action_data['complete_with_errors'] = true;

			return Automator()->complete->action( $user_id, $action_data, $recipe_id, $error_message );

		}

		$args = apply_filters(
			'automator_send_webhook_remote_args',
			array(
				'method'  => $request_type,
				'body'    => $fields,
				'timeout' => '30',
			),
			$data,


Scroll to Top