http post request afterPageCreate

Post Reply
puschmie
Ssr. Bludit
Posts: 10
Joined: Thu Oct 29, 2020 12:12 pm
Location: Vienna
Contact:

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!
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
puschmie
Ssr. Bludit
Posts: 10
Joined: Thu Oct 29, 2020 12:12 pm
Location: Vienna
Contact:

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!
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
puschmie
Ssr. Bludit
Posts: 10
Joined: Thu Oct 29, 2020 12:12 pm
Location: Vienna
Contact:

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.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Post Reply