-
-
Save patrickatwsrn/788d76d29e61045996ad0d48dc9d8b05 to your computer and use it in GitHub Desktop.
Very basic webhook for MODX, posts JSON to a URL. Works well with Zapier.
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 | |
// [[!WebHook? &secret=`dh730>soteW` &runsnippet=`updateSettings` ¶ms=`setting=savings`]] | |
$mySecret = $modx->getOption('secret', $scriptProperties); | |
$mySnippet = $modx->getOption('runsnippet', $scriptProperties); | |
$myParams = $modx->getOption('params', $scriptProperties); | |
$achunks = array_chunk(preg_split('/(=|,)/', $myParams), 2); | |
$myParams = array_combine(array_column($achunks, 0), array_column($achunks, 1)); | |
$webhookContent = ""; | |
$webhook = fopen('php://input' , 'rb'); | |
while (!feof($webhook)) { | |
$webhookContent .= fread($webhook, 4096); | |
} | |
fclose($webhook); | |
$newJSON = $modx->fromJSON($webhookContent); | |
$allParams = array(); | |
if(is_array($myParams)) | |
$allParams = array_merge($allParams, $myParams); | |
$allParams = array_merge($allParams, $newJSON); | |
if ($newJSON['secret'] == $mySecret) { | |
$modx->log(modX::LOG_LEVEL_ERROR, '[WebHook] ' . $webhookContent); | |
$output = $modx->runSnippet($mySnippet, $allParams); | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment