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 |
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
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.