How to Send the Numerical Values Through Webhooks

Overview

Do you need to make sure the numerical values sent through a webhook show up as a number instead of a string? By default, all numbers passed through using webhooks are sent through as a string instead of numbers. With a small snippet, you can easily convert these strings into numbers and we’ll show you how.

Setup

To ensure the numbers are sent through as numerical values, please copy and paste this code snippet to your site.

If you need assistance in adding snippets to your site, please see this tutorial.

/**
 * Send the numerical values through webhooks.
 *
 * @link https://wpforms.com/developers/how-to-send-the-numerical-values-through-webhooks/
 *
 */
function wpf_dev_webhooks_numeric_value( $filled_params, $params, $process ) {

    // Request Body params which values should be numeric.
	$numeric_values = [ 'age', 'custom_value' ];

	foreach ( $filled_params as $key => $param ) {
		if ( is_numeric( $param ) && in_array( $key, $numeric_values, true ) ) {
			$filled_params[ $key ] = (int) $param;
		}
	}

	return $filled_params;

    }

add_filter( 'wpforms_webhooks_process_fill_http_body_params_value', 'wpf_dev_webhooks_numeric_value', 10, 3);

Then just make sure your form is mapping the fields correctly in the form Settings.

now you can send numerical values through webhooks

And that’s all you need! Would you like to also include the Entry ID in your webhook? Take a look at our article on How to Send the Entry ID Through Webhooks.