Send leads to a webhook
You can send your Riddle leads and responses automatically to your marketing software or data warehouse for each person who completes your included lead generation form. Here's some more information about webhooks and APIs.
Set up the webhook
- Go to PUBLISH.
- Click on Save and connect data.
- Under Add integrations, find Webhook, and click on ADD.
- Enter the URL of your webhook endpoint into the Webhook URL field and click on CONTINUE.
For testing purposes we recommend creating a free webhook on https://webhook.site as this will allow you to inspect the data Riddle sends to the webhook. - A test lead will be sent automatically but you can retest by clicking on SEND.
- Click on CONTINUE.
Process the webhook
- Create a PHP file that receives the payload from Riddle and parses the data so you can send it on to a tool of your choice.
The following example takes the data from a simple 1 question Riddle with a single form field and writes that data into a MySQL database. - Add this code which will write the entire riddle data into the variable $payload
$payload = \file_get_contents('php://input');
- The webhook sends the data in JSON format. You can decode the JSON data with this code:
$payload = \json_decode($webhookContent, true);
- The Riddle data is now stored in an array in the $payload variable and you can access each data point like this example, which extracts the Riddle title:
$payload['data']['riddle'][0]['title']
- Here is a full example sending all data from the Riddle to a MySQL Database. The entire code was generated with the help of ChatGPT. To create your own code with ChatGPT you can follow these steps:
- Send a webhook from your Riddle to https://webhook.site.
- Copy the JSON from webhook.site.
- In ChatGPT ask "create PHP code to process this data (copy your JSON) from a webhook with PHP.
<?php
// Parse the JSON payload into an associative array from Riddle "riddleId": "XXXXXXX",
//$payload = json_decode($_POST['payload'], true);
$payload = json_decode(file_get_contents('php://input'), true);
// Connect to MySQL server
$servername = "localhost";
$username = "put your username name";
$password = "put your password here";
$dbname = "put your database name here";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Extract data points from the payload and sanitize them for safe insertion into the database
$uniqueId = mysqli_real_escape_string($conn, $payload['uniqueId']);
$riddleId = mysqli_real_escape_string($conn, $payload['riddleId']);
$identifier = mysqli_real_escape_string($conn, $payload['identifier']);
$version = mysqli_real_escape_string($conn, $payload['version']);
$createdAt = mysqli_real_escape_string($conn, $payload['createdAt']);
$riddleTitle = mysqli_real_escape_string($conn, $payload['data']['riddle'][0]['title']);
$riddleBlockId = mysqli_real_escape_string($conn, $payload['data']['riddle'][0]['blockId']);
$riddleValue = mysqli_real_escape_string($conn, $payload['data']['riddle'][0]['value'][0]);
$formTitle = mysqli_real_escape_string($conn, $payload['data']['form'][0]['title']);
$formBlockId = mysqli_real_escape_string($conn, $payload['data']['form'][0]['blockId']);
$formFieldId = mysqli_real_escape_string($conn, $payload['data']['form'][0]['fieldId']);
$formValue = mysqli_real_escape_string($conn, $payload['data']['form'][0]['value']);
$resultBlockId = mysqli_real_escape_string($conn, $payload['data']['result']['blockId']);
$resultTitle = mysqli_real_escape_string($conn, $payload['data']['result']['title']);
$resultScore = mysqli_real_escape_string($conn, $payload['data']['result']['score']);
$resultMaxScore = mysqli_real_escape_string($conn, $payload['data']['result']['maxScore']);
// Insert data into MySQL database
$sql = "INSERT INTO SampleWebhook (uniqueId, riddleId, identifier, version, createdAt, riddleTitle, riddleBlockId, riddleValue, formTitle, formBlockId, formFieldId, formValue, resultBlockId, resultTitle, resultScore, resultMaxScore)
VALUES ('$uniqueId', '$riddleId', '$identifier', '$version', '$createdAt', '$riddleTitle', '$riddleBlockId', '$riddleValue', '$formTitle', '$formBlockId', '$formFieldId', '$formValue', '$resultBlockId', '$resultTitle', '$resultScore', '$resultMaxScore')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Please note that the code above is very specific to a Riddle quiz with one question and one form field. You need to adjust your code to capture the data from your Riddle. By using https://webhook.site you will get a good overview of all the data your Riddle sends to the webhook.
Table of Contents