简体   繁体   中英

HubSpot Webhook to PHP on aws ec2 ubuntu server

I am working with an aws ec2 server (ubuntu). It is set to open so for all traffic. I am trying to get my Webhook from HubSpot to connect to my php page for collecting data. I have tested this webhook with the recommended RequestBin site and all the data comes through just fine. So this leads to think its my code or maybe the use of the SSL on the server that is used to connect to it via terminal.

my php code is ...

<?php

# taking data from HubSpot's webhook 

//$hookData = json_decode(file_get_contents("php://input"), ture);
//$_POST = json_decode(file_get_contents("http://requestb.in/150jn861")); // does not get anything
//$_POST = file_get_contents('http://requestb.in/150jn861'); // writes to file the string "ok" 
$_POST = json_decode(file_get_contents("php://input"), ture);
$file = fopen("datadump1.txt", "w");
fwrite($file, $_POST);
fclose($file);
var_dump($_POST); // test input
echo "\nTest completed\n"; 
?>

I have found 2 other posts on here for webhooks and hubspot but the fix did not work. As you can see I have been testing multiple things but have not gotten anything to work. Since this is aws ec2 I cannot use the var_dump or echo to really test as good as I would like. I have never used this type of environment before. Thank you in advance for any help you can give.

This was a big over sight on my part. I was not accounting for the permissions in ubuntu. after testing with local files and cRUL to my testPHP file I wound this out. changed permissions with "sudo chmod -R 777 /var/www/html/testPHP.php" then with the local POST I was a file was created and data was in it. here is my code for anyone that wants it; and DON'T FORGET THE PERMISSIONS IF IN UBUNTU. HAHAHA

<?php

# taking data from HubSpot's webhook 

$hookData = file_get_contents("php://input");

$file = fopen('datadump.json','w') or die("Unable to open file!");
fwrite($file, $hookData);
fclose($file);

//var_dump($hookData); // test input
echo "\nTest completed\n" . $hookData; 
?>

in my POST file...

?php

$myObj = null;
$myObj->name = "Name";
$myObj->age = 32;
$myObj->city = "New York";

$myJSON = json_encode($myObj);


//API Url
$url = 'REMOVED; put your URL here';

//Initiate cURL.
$ch = curl_init($url);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

//Execute the request
$result = curl_exec($ch);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM