Skip to content

Instantly share code, notes, and snippets.

@escopecz
Last active October 29, 2021 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@IADDIC
Copy link

IADDIC commented Feb 15, 2017

@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

@BillPackard
Copy link

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.

@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