phpwebhooks

How to get data from webhook with content-type: application/x-www-form-urlencoded;charset=UTF-8?


I have setup a webhook in zoho crm but when ever i try to fetch the data with json_decode(file_get_contents("php://input"), true) it is always blank. From the look of the content-type the data is not json, i ahve tried everything and i still can't get the data from the webhook.

Any help is much appreciated.

Capture of HTTP POST Request: enter image description here

add_action( 'rest_api_init', 'register_api_hooks' );

function register_api_hooks() {
    register_rest_route( 'ep-to-zoho-crm/v1', '/updatecompany', array(
        'methods'  => 'POST',
        'callback' => 'webhook_listener',
    ));
};

function webhook_listener($request){
    // We don't want to process if it did not come from webhook
    //if( !isset( $_GET['companyid'] ) ) { return; }

    //$data = $request->get_param( 'companyid' );

    if ( isset( $_REQUEST['companyid'] ) ) {
        file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', 'works');
    }else{
        file_put_contents(plugin_dir_path( __FILE__ ).'invalid.txt', 'invalid');
    } 

    /*$data = $_POST['companyid'];

    file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', $data);


    $json_string = json_encode($_POST);

    $save = file_put_contents(plugin_dir_path( __FILE__ ).'crm.json', $json_string);*/
}
add_action( 'init', 'webhook_listener' );

and then my webhook url looks like this https://example.com/wp-json/ep-to-zoho-crm/v1/updatecompany


Solution

  • This issue was my server was not configured correctly and so the data was being blocked when sent to my webhook url.