How to Send the Numerical Values Through Webhooks

Overview

Would you like to send numerical values through webhooks? By default, when you pass values through webhooks, they are sent as strings and not numbers. With a simple snippet, you can effortlessly convert these strings into numerical values, and we’ll guide you through the process.

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.
    // List each variable that you want as a number and not a string here separated by a comma and listed in single quotes
    $numeric_values = [ 'experience', 'form_id' ];
 
    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. For the purpose of this documentation, we’re passing through two variables. One is experience and another is form_id. Just make sure to include each variable name in the snippet above wrapped in single quotes and separated by a comma for each variable you want to convert from a string to a number.

map the fields to your appropriate values

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.