Turns out I'm trying to integrate witei's CRM into a website. According to the witei documentation, I must indicate a url (webhook), where I want to receive the information of the properties that has changed, so that I can keep the properties of my website updated.
The information is sent through the POST method and the service works because it returns the data in JSON format, testing through the https://beeceptor.com/ service (which generates a temporary endpoint).
The fact is that according to what I have read (or I understood), I have to create an endpoint in my Wordpress, following the steps indicated in the wordpress documentation: https://developer.wordpress.org/rest- api/extending-the-rest-api/adding-custom-endpoints/
My question is: Am I in the right direction? If so ... With my endpoint created, do I have to create any extra file? or just including the function 'register_rest_route', dont need to make anything else? I have tried following instructions but I always get error 404.
The code involved for that is:
//Testing webhook
add_action( 'rest_api_init', function () {
register_rest_route( 'real-estate-lite/v1', '/endpoint', array(
'methods' => 'POST',
'callback' => 'my_awesome_func',
) );
} );
function my_awesome_func( $request ) {
$data = $request->get_json_params();
error_log( print_r( $data, true ) );
}
And in Witei CRM I get this result:
Can anyone help me with this? or just drive me in the right direction? Thank you!
example.com/wp-json/real-estate-lite/v1/endpoint
?