-3

I'm creating a script that will receive response from Zoho Sign Webhook. I use the following condition to trigger the Webhook :

enter image description here

I am able to receive the hit into the Callback URL by saving every response into the database. I'm using a simple code below :

<?php 

$data = file_get_contents('php://input');
$escape = mysqli_real_escape_string($conn, $data);

$q=mysqli_query($conn,"INSERT INTO `response` VALUES ('','$escape')");
if($q){
    echo "success";
}else{
    echo "failed - ".mysqli_error($conn);
}

?>

But i always get empty response using the script above. The $data, $post, or $get variable is always empty.

I tried to find the documentation on the Zoho and other question on stackoverflow but i only can get this discussion here and here. Which is not solving my problem.

Any other way to get the response from Zoho Sign Webhook using PHP?

apripuppey
  • 111
  • 1
  • 3
  • 13
  • Pretty terrible way to try and log data, it would fail as soon as one of the variables would contain a single quote. – CBroe May 31 '21 at 07:22
  • Your webhook URL appears to end in `-webhook` – are you sure that is _directly_ reachable, without any external redirects (which would likely make you loose the POST body)? Not missing a trailing slash or something maybe? – CBroe May 31 '21 at 07:23
  • Hi @CBroe, yes, sorry. It's just a plain script to test if the webhook is working or not. And it is reachable. The proof is the records in my database is inscreased everytime the selection action in Zoho Sign is executed (for example, sending documents to sign). I just want to dump whatever the Zoho Sign webhook sends to my callback URL. And for the variable one, i just want to dump every response into one string variable (i will add the escape function later) – apripuppey May 31 '21 at 08:14
  • Yes, but is it reachable _directly_, or does the server maybe respond with a redirect to a (slightly) different URL first? $_GET and _$POST _should_ be empty, assuming this is not adding any query string parameters, and the data is send as JSON. And `php://input` will not contain anything either, _if_ your system issued a redirect first, that the remote party then followed by making a GET request. – CBroe May 31 '21 at 08:17
  • Sorry @CBroe, i don't really understand what's that mean by reachable directly, could you elaborate more about it? my callback URL is just a plain subdomain URL with index.php file inside it. So everytime the callback URL is called, then it will execute the script above directly. Even if you just access the callback URL directly on browser, there's no limitation on it. So based on the script above, it will just save anything into the database even if it's empty. – apripuppey May 31 '21 at 08:25
  • 1
    _“my callback URL is just a plain subdomain URL with index.php file inside it”_ - then you need to specify it with a trailing slash, otherwise your server _will_ redirect `/directoryname` to `/directoryname/` first, and then you lose the data. – CBroe May 31 '21 at 08:43
  • Ahh i get it, thanks ! as soon as i change the webhook callback URL with trailing slash it's now working and the response can now seen in the database record. – apripuppey May 31 '21 at 08:52

1 Answers1

1

Thanks @CBroe for the explanation, the problem with my callback was because of missing trailing slash on my callback URL:

http://sub.domain.com/callback

and the problem solved when i change it into :

http://sub.domain.com/callback/
apripuppey
  • 111
  • 1
  • 3
  • 13