Home:ALL Converter>What data is POSTed to a shippo webhook?

What data is POSTed to a shippo webhook?

Ask Time:2017-08-31T07:53:17         Author:MikeGA

Json Formatter

I would like to implement a shippo webhook in order to know the delivery status of my shipments, their documentation is a little unclear... I don't know what information will be passed to my script

I have setup a test URL and a live one and have added those to my account, in API -> Webhooks.

Whenever my script is requested either via the live or test URLs I get empty arrays, no data. Please help me figure this out. Anyone from Shippo??

Here is what I have so far:

<?php

namespace MW\PublicBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


class ShippoController extends Controller
{
    /**
     * @Route("/shippo/", name="shippo_web_hook")
     * @Method("GET|POST")
     */
    public function webHookAction(Request $request)
    {
        if ($request->getMethod() == 'POST'){
            $post = $request->request->all();
        } elseif ($request->getMethod() == 'GET'){
            $post = $request->query->all();
        }
        file_put_contents(__DIR__ . '/shippo.txt', print_r($post,true));

        $mailer = $this->get('swiftmailer.mailer.transactional');
        $messageObject = \Swift_Message::newInstance()
            ->setSubject('Shippo Webhook Posted DATA')
            ->setFrom('[email protected]')
            ->setTo('[email protected]')
            ->setBody(print_r($post,true) . "\n" . print_r($_REQUEST,true) . "\n" . print_r($_POST,true));
        try {
            $mailer->send($messageObject);

        } catch (\Exception $e){

        }

        return new Response('OK');
    }


}

As you can see I should be able to catch some incoming data but I get nothing but empty arrays..

Author:MikeGA,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45971304/what-data-is-posted-to-a-shippo-webhook
MikeGA :

Indeed my script is receiving straight up JSON, thank you to mootrichard for sharing the requestb.in tool, with it I was able to see all the headers and data sent, just for future reference this is what I got.\n\n\n\nnamespace MW\\PublicBundle\\Controller;\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Method;\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\n\nclass ShippoController extends Controller\n{\n /**\n * @Route(\"/shippo/\", name=\"shippo_web_hook\")\n * @Method(\"GET|POST\")\n */\n public function webHookAction(Request $request)\n {\n $headers = $request->headers->all();\n $content = $request->getContent();\n if (!empty($content))\n {\n $post = json_decode($content, true);\n }\n if (isset($headers['x-shippo-event'][0]) && $headers['x-shippo-event'][0] == 'track_updated' &&\n (isset($headers['content-type'][0]) && $headers['content-type'][0] == 'application/json')){\n\n if (count($post) > 0) {\n file_put_contents(__DIR__ . '/shippo.txt', print_r($headers, true) . \"\\n\\n\\n\" . print_r($post, true));\n\n }\n\n\n }\n\n\n\n\n\n return new Response('OK');\n }\n\n\n}\n\n\nAnd the contents of shippo.txt is:\n\n Array\n(\n [host] => Array\n (\n [0] => ******\n )\n\n [user-agent] => Array\n (\n [0] => python-requests/2.9.1\n )\n\n [content-length] => Array\n (\n [0] => 1021\n )\n\n [accept] => Array\n (\n [0] => */*\n )\n\n [accept-encoding] => Array\n (\n [0] => gzip, deflate\n )\n\n [content-type] => Array\n (\n [0] => application/json\n )\n\n [shippo-api-version] => Array\n (\n [0] => 2014-02-11\n )\n\n [x-forwarded-for] => Array\n (\n [0] => **.**.***.**\n )\n\n [x-original-host] => Array\n (\n [0] => *****\n )\n\n [x-shippo-event] => Array\n (\n [0] => track_updated\n )\n\n [x-php-ob-level] => Array\n (\n [0] => 0\n )\n\n)\n\n\n\nArray\n(\n [messages] => Array\n (\n )\n\n [carrier] => usps\n [tracking_number] => 123\n [address_from] => Array\n (\n [city] => Las Vegas\n [state] => NV\n [zip] => 89101\n [country] => US\n )\n\n [address_to] => Array\n (\n [city] => Spotsylvania\n [state] => VA\n [zip] => 22551\n [country] => US\n )\n\n [eta] => 2017-09-05T01:35:10.231\n [original_eta] => 2017-09-05T01:35:10.231\n [servicelevel] => Array\n (\n [token] => usps_priority\n [name] => Priority Mail\n )\n\n [metadata] => Shippo test webhook\n [tracking_status] => Array\n (\n [status] => UNKNOWN\n [object_created] => 2017-08-31T01:35:10.240\n [status_date] => 2017-08-31T01:35:10.240\n [object_id] => ac0e0c060d6e43b295c460414ebc831f\n [location] => Array\n (\n [city] => Las Vegas\n [state] => NV\n [zip] => 89101\n [country] => US\n )\n\n [status_details] => testing\n )\n\n [tracking_history] => Array\n (\n [0] => Array\n (\n [status] => UNKNOWN\n [object_created] => 2017-08-31T01:35:10.240\n [status_date] => 2017-08-31T01:35:10.240\n [object_id] => ac0e0c060d6e43b295c460414ebc831f\n [location] => Array\n (\n [city] => Las Vegas\n [state] => NV\n [zip] => 89101\n [country] => US\n )\n\n [status_details] => testing\n )\n\n )\n\n [transaction] =>\n)\n",
2017-08-31T01:43:22
yy