How to Use Gravity Forms Webhooks (with Code Examples)

Gravity form webhooks

If you’ve ever wanted to connect Gravity Forms to third-party apps or APIs, webhooks are your best friend. They let you send form data instantly to another service — no plugins or email notifications required.

🚀 What Is a Webhook?

A webhook is an HTTP request triggered by an event — in this case, a form submission. Gravity Forms sends the form data to a specified URL, often in JSON format.

🛠️ How to Enable Webhooks in Gravity Forms

  • Make sure the Gravity Forms Webhooks Add-On is installed and activated (available with the Elite license).
  • Go to Forms → Settings → Webhooks on the form you want to connect.
  • Click “Add New” and configure the settings.

Here’s a basic example of a webhook sending data to a POST endpoint:

POST https://api.example.com/submit-form

{
  "name": "Jon Imms",
  "email": "jon@example.com",
  "comments": "Loving your Gravity Forms posts!"
}

🔐 Adding Authentication Headers

Need to secure your endpoint with a Bearer token? Just add it in the “Request Headers” section:

Authorization: Bearer YOUR_SECRET_TOKEN

📥 Capturing the Webhook (Custom Endpoint)

Want to receive Gravity Forms data inside your WordPress site? Register a custom REST endpoint like this:

add_action('rest_api_init', function () {
  register_rest_route('myplugin/v1', '/webhook/', [
    'methods'  => 'POST',
    'callback' => 'myplugin_handle_webhook',
    'permission_callback' => '__return_true',
  ]);
});

function myplugin_handle_webhook($request) {
  $data = $request->get_json_params();
  error_log('Webhook received: ' . print_r($data, true));
  return rest_ensure_response(['status' => 'received']);
}

📤 Sending Webhooks After Submission (PHP)

If you want more control than the UI allows, you can send your own webhooks using PHP:

add_action('gform_after_submission_5', function ($entry, $form) {
  $payload = [
    'name' => rgar($entry, '1'),
    'email' => rgar($entry, '2'),
    'message' => rgar($entry, '3'),
  ];

  $response = wp_remote_post('https://api.example.com/webhook', [
    'headers' => [
      'Authorization' => 'Bearer your-token',
      'Content-Type'  => 'application/json',
    ],
    'body' => wp_json_encode($payload),
  ]);

  if (is_wp_error($response)) {
    error_log('Webhook failed: ' . $response->get_error_message());
  }
}, 10, 2);

🧪 Testing Tips

  • Use Webhook.site or RequestBin to inspect payloads live.
  • Check your browser console or logs for 403 errors (auth issues).
  • Enable Gravity Forms logging under Forms → Settings → Logging to debug.

💡 Use Cases

  • Send form leads to a CRM like Zoho or Salesforce
  • Trigger automated emails or Slack messages
  • Push support requests to HelpScout or Trello

Webhooks give you incredible flexibility — especially when paired with conditional logic or add-ons like Gravity Flow.

In future posts, I’ll go deeper into use cases like two-way sync, lead tagging, and webhook security best practices.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *