I'm using some simple code to record everything passed to a webhook processing script.
<?
// Write it down
$file = "../../../data/webhook-shopify-from-shipstation.log";
$data = json_encode($_REQUEST);
file_put_contents($file, $data . "\n",FILE_APPEND);
//
$json = file_get_contents('php://input');
$obj = json_decode($json);
if(strlen($obj) == 0){
echo "Fail";
exit;
}
if(isJson($obj)){
$filename = $file;
$somecontent = $obj . "\n";
// Lets make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example were opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// thats where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
else{
echo "Not valid JSON";
}
function isJson($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
As you can see by writing down any http request (post / get or other)...
And then looking for the JSON body if there is one, and writing that down as well.. You would think that I would get some data.
If i goto the webhook - i show up in the log, if i pass anything to the webhook, i showup in the log.. If i pass json to the webhook it goes in the log.
However.. I've never received a webhook on the target url for the SHIP_NOTIFY event.
My Overall Scenario in which I need a webhook (and later i'll probably code a sync tool as well).
I have a shopify store that carries both products that we fullfill in house, and some that are thru drop ship distributing. These orders are sent into shipstation via the shipstation shopify application.
I don't want to manually split orders, it confuses the staff to do this and just ends up costing money. So what I've done is create a second warehouse "DROPSHIPPING" and a send from location "DROPSHIPPING".. Via the API I read in the original order, and then delete it, and create two new orders.
One with the Dropshipping products (assigned to the DROPSHIPPING warehouse), and another for the IN house warehouse.
Being that shipstation does not allow me to edit the original order key, i have to generate a new order key for each, and then i use the OrderNumber for the inhouse, and for the dropshipping order I append -1 to mimic the shipstation effect of splitting an order.
This is not ideal, but it works.
So once the order is shipped, I'll end up coding this webhook to mark the order shipped in Shopify.
Has anyone got the shipstation webhooks to actually work?