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/
I have been trying to get a json response body when webhook hit on my URL but failing. This is my controller method
public function sendSMS(Request $request){
$response = json_decode(file_get_contents('php://input'));
Storage::disk('local')->put('file.txt', Response::json($response));
}
It always save a empty response in .txt. Can you help me out.
there have lots of reasons you get errors here.
I suggest you try debug the following reasons:
dump(file_get_contents('php://input')) check if the post is valid json
make sure your file file.txt is writable
make sure Storage configuration is correct
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']
);
I'm trying to send some form data as a JSON object to a sample app on Force.com. I get the form data using jQuery and POST it to a PHP file on my server which then sends it to the sample app linked above. The response I get from the sample app however tells me that I'm making some mistakes along the way.
The PHP file that talks to the sample Force.com app:
<?php
$url = 'https://cmsamp.secure.force.com/GenericApp/services/apexrest/GenericApp';
$data = $_POST[ 'data'];
$options = array('http' => array('method' => 'POST','content' => http_build_query($data)));
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>
Client-side jQuery code that posts form data to the PHP file:
var sample_form_data = {"attributes":{"type":"Generic_App__c"},"Application_Type__c":"iPay","Return_Email__c":"lsmith#cmsrep.com","Name":"Bus Test","ACHRejectFee__c":"123456789","ApplicationDate__c":"2000-01-01","BusinessPhone__c":"(555) 123-4567","Email__c":"thetest#testemail.com","InternetPercentage2__c":"0","MailingState__c":"CA","MOTO7__c":"true","NumOfLocations__c":"15"};
$.post( url, { data: JSON.stringify( sample_form_data ) }, function( result ) {
console.log( result );
});
The response from I get from the Force.com app:
"No content to map to Object due to end of inputInsert failed.
First exception on row 0;
first error: REQUIRED_FIELD_MISSING,
Required fields are missing: [Name]: [Name]"
Desired "success" response:
"Success:
Generic App Object: Bus Test; was successfully created and inserted"
This is the output of var_dump($data) in the php code (line breaks added for readability:
string(405)
"{\"attributes\":
{\"type\":\"Generic_App__c\"},
\"Application_Type__c\":\"iPay\",
\"Return_Email__c\":\"lsmith#cmsrep.com\",
\"Name\":\"Bus Test\",
\"ACHRejectFee__c\":\"123456789\",
\"ApplicationDate__c\":\"2000-01-01\",
\"BusinessPhone__c\":\"(555) 123-4567\",
\"Email__c\":\"thetest#testemail.com\",
\"InternetPercentage2__c\":\"0\",
\"MailingState__c\":\"CA\",
\"MOTO7__c\":\"true\",
\"NumOfLocations__c\":\"15\"
}"
The generic app just expects to get a JSON object with the proper fields. When I submit the following through a REST client it works as intended (again, line breaks added for readability):
{"attributes":
{"type":"Generic_App__c"},
"Application_Type__c":"iPay",
"Return_Email__c":"test#example.org",
"Name":"Bus Test",
"ACHRejectFee__c":"123456789",
"ApplicationDate__c":"2000-01-01",
"BusinessPhone__c":"(555) 123-4567",
"Email__c":"thetest#testemail.com",
"InternetPercentage2__c":"0",
"MailingState__c":"CA",
"MOTO7__c":"true",
"NumOfLocations__c":"15"}
Anyone have ideas on how to solve this?
From the looks of those var_dumps, I'd say you need to strip those slashes out of $data before you use it. Try stripslashes.
http_build_query also expects an array. Since your data is already a json string, I think you should probably omit it. You may need to url encode it, but you should just use the regular urlencode function for that.
Also, I'm not familiar with the php context mechanism you're using and I'm deeply unsatisfied with the php.net documentation, but I can't shake this nagging feeling that the 'content' => $data is doing something more than just setting the content. Do you have a good documentation link for the stream contexts actually using the 'content' option?
so my problem is I'm calling the Foursquare API with this GET request:
https://api.foursquare.com/v2/venues/4b522afaf964a5200b6d27e3?client_id=".$client_id."&client_secret=".$client_secret
And I don't know how to parse the results to display what I need. Typing it into the browser with client ID and client secret gives a page of correct results so I know the URL is correct. The problem is in this part of my code:
$json = json_decode($response);
foreach ($json->response->venue as $result)
{
echo $result->name.' - '.$result->location->address.' '.$result->location->city."<p />";
}
Here $response is the result from the GET request which I am trying to parse as JSON and display the name, address and city variables. Does anyone know my problem? Maybe the result returned isn't JSON or I'm structuring my parse wrongly? Any help would be very gratefully received. Thanks!
you need to pass a "v=20120319" parameter in you call to the endpoint, otherwise the server will fail to know when you wrote the code and translate that to a certain API version it will use.
https://developer.foursquare.com/overview/versioning