How to Send the Entry ID Through Webhooks

Overview

Would you like to pass the entry ID number from your form submission to an external source using the Webhooks addon? This can be easily done through a PHP filter with WPForms. In this tutorial, we’ll show you how you can send the entry ID as part of your webhook.

Setup

Just copy and paste this snippet to your site. For any help in adding snippets to your site, please see this tutorial.

/**
 * Send the entry id in webhook request.
 *
 * @link https://wpforms.com/developers/how-to-send-field-values-with-webhooks/
 *
 */
function wpf_dev_webhooks_process_delivery_request_options($options, $webhook_data, $fields, $form_data, $entry_id) {
        if ( ! wpforms_show_fields_options_setting() ) {
            return $options;
        }
        //Only run on form ID 86
        if ( empty( $form_data['id'] || $form_data['id'] !== 86 ) ) {
            return $options;
        }
        if (
            empty( $options['body'] ) ||
            empty( $webhook_data['body'] ) ||
            empty( $fields )
        ) {
            return $options;
        }
        $body = ! is_array( $options['body'] ) ? json_decode( $options['body'], true ) : $options['body'];
        // Create a new entry and assign the entry_id
	    $body['entry_id'] = $entry_id;
        // Format request data.
        if (
            ! empty( $options['method'] ) &&
            $options['method'] !== 'GET' &&
            $webhook_data['format'] === 'json'
        ) {
            // Encode request body.
            $options['body'] = wp_json_encode( $body );
        }
        return $options;
    }
add_filter( 'wpforms_webhooks_process_delivery_request_options', 'wpf_dev_webhooks_process_delivery_request_options', 10, 5);

And that’s it! You can now pass the entry ID through your webhook. Would you like to have autofocus on your form when the page loads? Check out our article on How to Add Autofocus on Your Form.