Last active
October 29, 2021 12:57
-
-
Save escopecz/0d9adba753300b88326d to your computer and use it in GitHub Desktop.
A simple script to log a Mautic webhook request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A helper class to log and get the Mautic webhook request | |
*/ | |
class webhookTest { | |
/** | |
* Log a message to a file | |
* | |
* @param mixed $message | |
* @param string $type [info|error|request] | |
*/ | |
public function log($message, $type = 'info') | |
{ | |
$prefix = 'webhookLog_'; | |
$file = $type . '.log'; | |
$date = new DateTime(); | |
error_log($date->format('Y-m-d H:i:s') . ' ' . $message . "\n\n", 3, $prefix . $file); | |
} | |
/** | |
* Get the request JSON object and log the request | |
* | |
* @return object | |
*/ | |
public function getRequest() | |
{ | |
$rawData = file_get_contents("php://input"); | |
$headers = apache_request_headers(); | |
$this->log(print_r($headers, true), 'headers'); | |
$this->log($rawData, 'request'); | |
return json_decode($rawData); | |
} | |
} | |
$webhook = new webhookTest; | |
$requestData = $webhook->getRequest(); | |
// @todo Process the $requestData as needed |
@escopecz do you know how to send the result to goole sheets? I would like to capture data in a google sheet but I am unfamiliar with how that is accomplished.
Thanks, Rich
When go to Create new webhook and write webhook POST Url this one: https://---mautic-dir------/webhookTest.php after press Send Test Payload have a red error message: Error Detected.
Since this script I learned there are simpler ways how to test webhooks. Google for "request bin" or "post bin" to find the right mutation of the tool.
Wow been struggling with Kajabi webhook payload debugging until I found this. Works like a charm thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is meant to ensure that the webhook is working and as a starting point to handle the webhook's payload. It will log every request to a log file so you know what is going on.
How to use it
http://example.com/webhookTest.php