You are here

Nation Builder Webhooks: Simple Example

Submitted by Nicole on August 15, 2014 - 2:34pm

This is a simple example of a webhook in Nation Builder. This webhook is set to be triggered anytime a person is changed. Our script simple decodes the data Nation Builder sends, and sends an email containing some of the data from the person changed. Note that this expects a "Version 4" payload from NationBuilder.

  1. <?php
  2. /*
  3.     Simple Webhook to email the contents of a person being created
  4.     nicole@richiroutreach.com
  5.     08/15/2014
  6. */
  7.  
  8. // Get the data from NationBuilder's POST
  9. $data = file_get_contents('php://input');
  10.  
  11. // Decode the JSON returned
  12. $data = json_decode(stripslashes($data));
  13.  
  14. // Get the data we want to email
  15. $first_name = $data->payload->person->first_name;
  16. $last_name = $data->payload->person->last_name;
  17. $email = $data->payload->person->email;
  18. $nid = $data->payload->person->id;
  19. $address = $data->payload->person->billing_address;
  20. $tags = $data->payload->person->tags;
  21.  
  22. // Tags is an array, so lets turn it into a string
  23. $tags = implode($tags, ", ");
  24.  
  25. // Compose our email message
  26. $message = "A new ActionNC.org tenant rights signup has been created.\n"
  27.     . "\tFirst name: $first_name\n"
  28.     . "\tLast name: $last_name \n"
  29.     . "\tNationBuilder ID: $nid \n"
  30.     . "\tEmail: $email\n"
  31.     . "\tAddress: $address\n"
  32.     . "\tTag list: $tags \n" 
  33.     . " Visit https://actionnc.nationbuilder.com/admin/signups?yours=1 to determine if you need to follow up. \n";
  34.  
  35. // Set up some headers for the email
  36. $headers = "From: Test <test@example.com>\r\n";
  37.  
  38. // Use PHP's mailing function
  39. mail(test@example.com", "NationBuilder Webhook ", $message, $headers);
  40. ?>