Page 1 of 1

http post request afterPageCreate

Posted: Tue Aug 17, 2021 5:43 pm
by puschmie
Hi all!
I'm trying to create a plugin, that sends some custom field data to a node server, when a new page of a certain category is created. Somehow the request doesn't go out. For debugging purposes I removed the if clause to check for the category. Any ideas what could be wrong here?

Code: Select all

<?php
    
    class pluginEvents extends Plugin{

  

       public function afterPageCreate($key){
            
            $page = new Page($key);

           
            $url = "localhost:4000/event-create";

            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
            $headers = array(
               "Accept: application/json",
               "Content-Type: application/json",
            );
           curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
            
            $data = array("message"=>"Test MEssage");
            
             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            
            //for debug only!
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            
            $resp = curl_exec($curl);
            curl_close($curl);
            var_dump($resp);
                


           
      }
    }
?> 
edit: Is there a way to include a JS script with some jquery code in the new content view? I feel like that would be easier to handle, but I can't quite figure out from the documentation how to add code to the admin theme pages. Thanks!

Re: http post request afterPageCreate

Posted: Tue Aug 17, 2021 10:32 pm
by Edi
puschmie wrote: Tue Aug 17, 2021 5:43 pm I'm trying to create a plugin, that sends some custom field data to a node server, when a new page of a certain category is created. Somehow the request doesn't go out.
Is cURL activated? Is it the right port? Where does the script stop?
[Is there a way to include a JS script with some jquery code in the new content view?
An example is the plugin content ID:

https://plugins.bludit.com/plugin/content-id

Re: http post request afterPageCreate

Posted: Wed Aug 18, 2021 7:15 am
by puschmie
The code that I posted is the whole plugin so far.
What do you mean by "is curl activated"?
I'm running bludit in a docker container and made sure to build the image from the dockerfile on github and added package rh-php72-php-curl to the installation steps. Is there any further activation needed?
It is the right port and the container on that port is also listening (verified with postman).

The jquery example is really helpful, I might try that out. That plugin example also gave me a bit of a better understanding of how to alter the admin views with plugins. Might be good to include that as an example in the docs.
Thanks for your support!

Re: http post request afterPageCreate

Posted: Sat Aug 21, 2021 4:24 pm
by Edi
puschmie wrote: Wed Aug 18, 2021 7:15 am The code that I posted is the whole plugin so far.
What should the plugin do?
That plugin example also gave me a bit of a better understanding of how to alter the admin views with plugins. Might be good to include that as an example in the docs.
I don't think that it should be part of the documentation. It has not much to do with Bludit itself, rather with using jQuery. There are several tutorials about it.

Re: http post request afterPageCreate

Posted: Sat Aug 21, 2021 5:29 pm
by puschmie
The plugin is supposed to send custom field values on event pages to a node server for entry into a database and automated notification to event participants.

Re: http post request afterPageCreate

Posted: Sat Aug 21, 2021 6:55 pm
by Edi
Sorry. I'm not an API crack. :-(

How to request a page shows an example in the documentation:

https://docs.bludit.com/en/api/request- ... cular-page

But using cURL can sometimes be tricky.