Skip to content

Instantly share code, notes, and snippets.

@escopecz
Last active October 29, 2021 12:57
Show Gist options
  • Save escopecz/0d9adba753300b88326d to your computer and use it in GitHub Desktop.
Save escopecz/0d9adba753300b88326d to your computer and use it in GitHub Desktop.
A simple script to log a Mautic webhook request
<?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
Copy link
Author

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.

@fungayimakoni
Copy link

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