Zoho Sign Webhook - Receiving Response Using PHP - php

I'm creating a script that will receive response from Zoho Sign Webhook. I use the following condition to trigger the Webhook :
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?

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/

Related

Issue while trying to receive message notifications from Slack

About
I am trying to receive message posted on my server as soon as user post message the message in group or channel or direct in slack.
App Status
Code in the verified file where challenge was posted.
header('Content-type: application/json');
$myfile = fopen("test.txt", "w") or die("Unable to open file!");
$data = json_decode(file_get_contents('php://input'), true);
fwrite($myfile, $data["challenge"]);
fclose($myfile);
$json = '{"challenge":' . $data["challenge"] . '}';
echo json_encode(["challenge" => $json]);
Question
Now that the above url has been verified successfully, I am still not able to receive the posted messages. I was expecting messages posted at same url which was used to verify challenge parameter. Is that correct?
Am I missing anything retrieving the messages posted on my server?
Update - 1
Due to some reasons I am not even able to verify the url anymore. My server is not receiving any data. I am trying to save whatever is being posted my side but it is always blank everytime,
I think your assumptions are correct.
According to slack documentation you should be receiving posts with the given payload in this endpoint:
https://api.slack.com/apis/connections/events-api#the-events-api__receiving-events__events-dispatched-as-json
I'm still unsure how are you validating that this isn't the case though, if you kept the code above you would see no result of the post data sent by slack, also if you don't return a response status 200, slack will stop posting to this endpoint after 1 hour.
https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
Can you try adding test.php file something like:
<?php
// get all the POST requests
if ($_SERVER["REQUEST_METHOD"] == "POST") {
file_put_contents('test.json', json_encode($_POST, JSON_PRETTY_PRINT), FILE_APPEND);
// return 200
http_response_code(200);
echo json_encode(["success" => true]);
return;
}
At the very beginning, validate the url again and check if the requests start being saved on test.json.
Alternatively can you check if you web server is routing POST requests to this url?
Try using postman to validate that

PayPal Webhook sends no POST data

Configured my PayPal webhook successfully to be notified of all events.
PayPal calls my webhook (a simple script) when events occur... but does not send any POST data with it....
All PHP arrays are empty ($_POST, $_GET, $_REQUEST) except for $_SERVER of course.
What is going on? The webhook simulator says that the events are sent/queued succesfully...
The $_SERVER array contains the suggested HTTP_PAYPAL_... headers and everything.... but the $_POST array is empty.
My webhook is written as follows...
<?php
require ('./ace-includes/ace_log.php');
ace_log(print_r($_POST, true));
ace_log(print_r($_REQUEST, true));
ace_log(print_r($_GET, true));
ace_log(print_r($_SERVER, true));
ace_sendlog("NOTIFY SCRIPT CALLED");
?>
I figured it out....
You cannot use $_POST to get the data....
The data is contained in the HTTP file sent to the script.
In this case you MUST use
file_get_contents('php://input');
to get the data.
So for PayPal PHP webhooks you would do this....
$json = file_get_contents('php://input');
$data = json_decode($json);
This works and now I am getting all the data.
This really should be documented somewhere.... anywhere... but its not... and not obvious to an beginning PHP programmer.

PHP telegram bot, sendmessage webhook

I'm writing a telegram robot,
This is my code and I want the user receive the message which they send into the bot:
telegram.php :
<?php
class telegram {
public $token;
public function __construct($token)
{
$this->token = $token;
}
public function recievedText()
{
$text= json_decode(file_get_contents('php://input'),true);
return $text;
}
public function sendMessage($userid,$text)
{
$url='https://api.telegram.org/bot'.$this->token.'/sendMessage?chat_id='.$userid.'&text='.$text;
file_get_contents($url) ;
}
}
?>
index.php :
<?php
require ('config.php');
require('telegram.php');
$telegram = new telegram(TOKEN);
$result = $telegram->recievedText();
$userid = $result->message->from->id;
$text = $result->message->text;
$telegram->sendMessage($userid,$text) ;
?>
config.php :
<?php
define('TOKEN','----');
?>
and I have already set webhook and checked the SSL of my site via this and it was set,
I don't know where is the problem that when I send the message to the bot it doesn't send back any message!
You checked if you have ssl, but you don't check if you really use it. You also don't check what is the response from the request you do
file_get_contents($url) ;
change this line to:
$requestResponse = file_get_contents($url);
var_dump($http_response_header);
var_dump($requestResponse);
to see if you succeed sending the request at first.
Without the response It's just guessing what could go wrong.
You should see response code = 200 if everything is OK if other number not beginning with 2xx then you fail sending the requrest.
Read about HTTPS connections with file_get_contents(), or try to use cURL. Hint: Just for the debugging you can skip SSL verification so at least this problem at the beginning is eliminated. But remember to turn the verification back on after debugging!
If you do the request as GET query you need to encode the text before putting it at the url - use: urlencode() for that.
$url='https://api.telegram.org/bot'.$this->token.'/sendMessage?chat_id='.$userid.'&text='.$text;
change to
$url='https://api.telegram.org/bot'.$this->token.'/sendMessage?chat_id='. urlencode($userid) . '&text='.urlencode($text);
or even better make use of http_build_query() and encode this way all variable besides $this->token. Given link has a plain example so I'll skip giving you code.
You need to set webhook before anything else. Fire a POST request using Postman to
https://api.telegram.org/bot/setWebhook
with Body parameter:
url: https://your-server/api-endpoint
drop_pending_updates : true (false) -> (optional) I use this to drop pending messages

problems with php POST - POST body is empty in login request

I am currently working on an APP that sends a post request to a server to login. The backend developer of my team is a bit slow so I thought why wouldn't I just set up some mock urls for testing the app.
I got a php file for the login which should return me a session when I enter correct data. Unfortunately I am stuck trying to get the JSON i post into some variables.
In fact, i don't see any data i receive. I've tried to use vardump on $_POST, $HTTP_RAW_POST_DATA as wel as file_get_contents("php://input"). I tried to decode the latter two with json_decode.
Some give me String(0) "" others give me NULL. In some cases i just got nothing.
Using retrofit i send a request to /login with a body of
{
"password":"password",
"username":"Marcel"
}
However when what i get as return is nothing. The my php code is only getting the and returning a json object with a session token
if(!empty($_POST["username"]) && !empty($_POST["password"])){
$id= array('SESSION_ID' => 'random_session_token_0015');
echo json_encode($id);
}
This code example does not give me any return. Using print_r($_POST); i will get an empty array like array().
$json = file_get_contents('php://input');
$object = json_decode($json);
var_dump($object);
This code example does give me any return, but it is NULL. $HTTP_RAW_POST_DATA had the same result as the latter example.
I'm quite stuck in this problem, anyone there to help?
ps. aks if you need more info
I resolved the same problem by making sure I send the "Content-Type: application/json" header to my Node.js server.
Try
file_get_contents(
'php://input',
false,
stream_context_get_default(),
0,
$_SERVER['CONTENT_LENGTH']
);

Parse.com after_save from Webhook produces invalid json

I'm seeing the following error in my Parse.com Error logs:
E2015-09-28T12:40:37.531Z]vWEB after_save triggered for MPPChatRoom for user gI8UxW2JNa:
Input: {"object":{"counter":0,"createdAt":"2015-09-18T12:35:28.195Z","description":"client at Milton","lastMessage":"VGVzdA==\n","lastUser":{"__type":"Pointer","className":"_User","objectId":"Eoi7gcQ4Rs"},"memberCount":2,"members":["Eoi7gcQ4Rs","gI8UxW2JNa"],"mppfile":{"__type":"Pointer","className":"MPPFile","objectId":"3tZWUNHXlf"},"objectId":"jZS5dhQPna","owner":{"__type":"Pointer","className":"_User","objectId":"Eoi7gcQ4Rs"},"roomId":"88b17cd0-63cd-40c7-8b7a-3b6d356768be","status":1,"title":"Tom Grey","updatedAction":{"__type":"Date","iso":"2015-09-18T12:59:19.995Z"},"updatedAt":"2015-09-28T12:40:37.528Z","user":{"__type":"Pointer","className":"_User","objectId":"gI8UxW2JNa"}}}
Result: Invalid JSON
I'm scratching my head over this as I don't have any custom after_save cloud code functions on that class. I do however have a webhook for the after_save on that class:
Webhook Type: afterSave,
Class: MPPChatRoom,
URL: https:// my domain /messagePush/parseMessagePush.php
As it is an after_save I can't control the input, and looking at the above input, I can't see anything wrong with the JSON either. The json above is valid when I copy and paste it into https://jsonformatter.curiousconcept.com/
Can anyone help?
EDIT 1:
I'm new to webhooks and I'm not a PHP dev so I'm assuming the PHP is producing the error, not Parse? Here is the initial code:
include "../includes/config.inc.php";
$sql_object = new sql_class('parseMessagePush.php');
ob_start();
echo "<pre>";
print_r($_POST);
print_r($_GET);
print_r($_SERVER);
print_r(json_decode(file_get_contents('php://input'), true));
$dataLog = json_decode(file_get_contents('php://input'), true);
I'm now thinking one of those json_decode calls is causing an exception. Though I don't see why Parse would send invalid json.
I think this issue was solved by echoing back JSON success data in the parseMessagePush.php file:
header("Content-Type: application/json");
$sucessData = array('status_code' => '200',"status_message" =>'success');
echo json_encode($sucessData);

Categories