Jump to content

webhook.php written to collect info refuses to write to local log file


Greywacke
 Share

Recommended Posts

hi all,

 

what is wrong with the following code that it does not write the following to log file when an item is updated using webhooks?

<?php/*timestamp	int			Sent as unix time (http://en.wikipedia.org/wiki/Unix_time)secretkey	string		If you provided a SecretKey it will be included here, otherwise this field is emptydata		hash		A data hash containing the same data as returned from a API call but as a POST parameter body.type		string		What type of data was changed(Contact, Action, Deal etc..)reason		string		What change triggered the Webhook(Created, Deleted, Updated etc..)*/function microtime_float() {    list($usec, $sec) = explode(" ", microtime());    return ((float)$usec + (float)$sec);}$time_start = microtime_float();$keys = file("/var/equote",FILE_USE_INCLUDE_PATH | FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);if ($_POST["secretkey"]==$keys[0]) {	$data = json_encode($_POST["data"],true);	$type = $_POST["type"];	$reason = $_POST["reason"];	// contact					{"data"=>"{"id"=>"51a8852aceb9976888000007", "pendingdeal"=>true, "starred"=>true, "owner"=>"51a88516ceb9976888000001", "type"=>"contact", "firstname"=>"Jane", "lastname"=>"Doe", "company"=>"Acme Inc.", "status"=>"customer", "tags"=>[], "photo_url"=>"https://opcrm-fd-us-west-1-51a896c4ceb997741c000006.s3.amazonaws.com/51a88516ceb9976888000001/51a8852cceb9976888000009/jane_doe.png", "next_actions"=>{"51a88516ceb9976888000001"=>[{"id"=>BSON::ObjectId('51c422aaceb997128700026c'), "name"=>"Contact Jane to confirm she has received our deal", "type"=>"date", "date"=>2013-06-26 00:00:00 UTC}]}, "company_id"=>nil}", "type"=>"contact", "reason"=>"updated", "secretkey"=>"mysecretkey", "timestamp"=>"1371810060"}	if ($type == "contact") {		switch ($reason) {			case "Created":		// Created		Object has been created.								break;			case "Updated":		// Updated		Object has been updated.								break;		}	}}$time_end = microtime_float();$time = $time_end - $time_start;print_r($_POST);// if (count($_POST)) error_log("rn".$time." second execution completed at ".date("Y/m/d H:i:s",time())."rn".print_r($_POST,true)."rn",3,dirname(__FILE__).DIRECTORY_SEPARATOR."webhook.log");?> 

the file is located in /var/www/performatix.co/production/public/webhook.php with an md5'd htaccess file as /var/equote containing two username/encoded password strings.

however whenever updating the onepage crm - however the array is always empty! what would be wrong here? this is on the onepage crm using the version 3.0 api...

Link to comment
Share on other sites

Maybe the user that PHP is running under doesn't have permission to read that file. Make sure that all error messages are being reported and that you're using the error log where you can check it for errors like that.

 

would i have to set permissions within the file function perhaps? the permissions are rw-r--r-- in winscp - and no it successfully gets the key and prints it from the file.

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

The file function doesn't have a way to specify permissions. I'm not sure exactly what the issue is. First you said this:

 

 

 

however whenever updating the onepage crm - however the array is always empty!

By "the array" I thought you were referring to the output of the file function, meaning that it couldn't read the file. But this:

 

 

 

and no it successfully gets the key and prints it from the file.

sounds like it does read the file. The code above only shows file reading, no writing. I'm confused about what the problem is. Is the error log set to the same file that you're reading?

 

 

 

the permissions are rw-r--r--

That means that everyone has read permission and only the file owner has write permission. If PHP is running as an account other than the file owner, then it won't be able to write to the file.

Link to comment
Share on other sites

this issue is still awaiting assistance from the 1pg developers - the apparent post data does not get posted as it should! :o

(the webhooks i am trying to integrate here - are still in beta...)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...