I’m trying to write a connector and processor for taking the response from a webhook. I’ve looked through documentation/forum posts tried using ChatGPT but getting really stuck.
I can’t seem to find any kind of tutorial for specifically implementing the response from a webhook. (In this instance I’m selling a digital course, and need the webhook to tell me when a payment has cleared so that I can then add the right permissions to the user so they can access the course on my site. I’m trying to get it working with Easycart).
I’m unsure exactly what needs to go in the connector/processor as I seem to find conflicting information with regards to revo-3. I’m also unclear exactly where I need to put the various files, as well as the url I would need to put in for the webhook.
I also don’t know how I can test whether I have everything hooked up correctly. I’ve tried putting error logs in but none seem to get triggered, which would suggest that I am not successfully triggering the connector.
Also, do I need to use a ‘namespace’?
I absolutely love MODX for how flexible it is, but find it to be not very intuitive if you don’t understand exactly what you need to do, and there are not any tutorials that make it clear enough to follow, especially if you are not already versed in this level of web development.
Any help would be appreciated especially if it could be a step by step, do this followed by that type of format.
I’m happy to do my research but really pulling a blank on how to get this to work.
I’m not sure that a connector/processor is the best approach here. These are normally just used to handle requests from within the MODX manager.
What exactly are the implementation details of this webhook that you’re trying to implement?
A POST-request that expects a JSON response?
The easiest way is probably just a MODX resource with an empty template and a “Content Type” of “JSON”, where you put an uncached custom snippet in the content that handles the request.
You could also just create a custom PHP file somewhere on your server that handles the webhook and loads MODX externally to interact with MODX.
Thanks for the response @halftrainedharry.
The developer told me that I would need to use a connector/processor, so that was why I was headed in that direction.
I can’t say without knowing more details about the webhook.
But yes, if the payload is JSON or $_POST doesn’t contain the data, then I suppose this is the way to read the payload.
Maybe I should elaborate more why I don’t think a connector/processor is the best option here.
A connector in MODX 3 should still work pretty much the same as in MODX 2. The file path is usually assets/components/<name of extra>/connector.php with code like this:
<?php
require_once dirname(__FILE__, 4).'/config.core.php';
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
require_once MODX_CONNECTORS_PATH.'index.php';
// load some custom classes or services or do other stuff
/* handle request */
$path = '...'; // define the path to your folder with the processors
$modx->request->handleRequest(array(
'processors_path' => $path,
'location' => '',
));
The ‘problem’ is, that there is some built-in security. From the documentation:
One is that the connectors are locked down and don’t allow anyone without a MODX manager session to access them. Secondly, all requests to connectors must pass a unique-to-your-site authorization key that prevents CRSF attacks. It can either be passed in the HTTP headers as ‘modAuth’, or in a REQUEST var as HTTP_MODAUTH.
The connector/processor expects certain request parameters to work properly. The “action” parameter to find the correct processor, “HTTP_MODAUTH” for security and maybe “ctx” to initialize the correct context.
As you won’t have these request parameters, you could try to set them directly in the connector, but I’m not sure if that even works in this use case.
Here is an example (from the SimpleSearch extra) that does something like that:
But if you really want to use a processor, I think it will be easier to just run $modx->runProcessor() directly.
Here is a possible example (from the FormIt extra):
Or (like I wrote in my previous post) you could just load MODX externally.
This is for example what the extra pdoTools does (so that more data can be loaded with AJAX in pdoPage):
I’m currently implementing just a standard php file on the server, and have got it to log the response from the easycart webhook, so now it’s on to loading MODX externally so that I can process the data appropriately. It seems the most sensible way to do it, but more importantly it’s currently working for me, and I understand what it’s doing!
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.