Closed mandargiftease closed 8 years ago
Thanks @mandargiftease We will work on this and reply you when we have an example.
We are sorry for the late reply. For solving your problem, you could use the following code to implement the webhook
<?php
// How-To:
// 1. Copy this file in your HTTP server DocumentRoot.
// 2. The webhook link maybe: http://www.example.com/webhook.php, paste in Aftership Dashboard->Settings->Webhook.
// 3. Set the trigger in Webhook setting page, like "In Transit", "Delivered". Aftership will make POST request based on your settings.
// 4. To test your webhook, just click the "Update" button in Webhook Setting page, aftership will send a dummy POST request to your webhook.
// Aftership will make a POST request to your webhook link with 'Content-Type: application/json' header,
// please use the "php://input" to get the post body, body is a JSON String.
// Reference: http://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to
// file_get_contents, need PHP 4 >= 4.3.0, PHP 5, PHP 7.
$inputJSON = file_get_contents("php://input");
// you will get a JOSN string as this api doc mentioned, https://www.aftership.com/docs/api/4/webhook
print_r($inputJSON);
// TO-DO: your logic, your code
You could find the webhook example in 5.0.7 version .
I have written a simple PHP program to dump all the request data received on webhook into the log file. However, I am unable to extract or see JSON data in the request. Here is the sample code that I am using:
`<?php require_once("../app/Mage.php"); Mage::app(); $array = $_POST; $msg = print_r($array, true);
$msg="Server: ".PHP_EOL.print_r($_SERVER,true).PHP_EOL."Request: ".PHP_EOL.print_r($_REQUEST, true).PHP_EOL."POST:".PHP_EOL.print_r($_POST,true).PHP_EOL."GET".PHP_EOL.print_r($_GET).PHP_EOL."Files:".print_r($_FILES);
Mage::log($msg, null, 'aftershiptrackingstatus.log', true); $data = file_get_contents('php://input'); var_dump($data); $msg="File Contents: ".PHP_EOL.print_r(json_decode($data, true)); Mage::log($msg, null, 'aftershiptrackingstatus.log', true); $msg="Raw Contents: ".PHP_EOL.print_r($HTTP_RAW_POST_DATA); Mage::log($msg, null, 'aftershiptrackingstatus.log', true); `
However in log file I am seeing only the headers and not the body part:
Can you help me with extracting the json data? Do you have any sample code for me to checkout?