Webhook code examples

Bash:

# You can also use wget
curl -X POST https://app.staging.shippit.com/api/3/webhook \
  -H 'Content-Type: application/json'

HTTP:

POST https://app.staging.shippit.com/api/3/webhook HTTP/1.1
Host: app.staging.shippit.com
Content-Type: application/json

Javascript:

const inputBody = '{
  "tracking_number": "PPYvZCTod5bkD",
  "expected_delivery_date": "2016-04-26T20:46:01+10:00",
  "tracking_url": "http://www.shippit.com/track/ppyvzctod5bkd",
  "current_state": "completed",
  "retailer_order_number": "WEYFEW232",
  "retailer_reference": "#OD12345",
  "courier_name": "Couriers Please",
  "courier_job_id": "CPAVZUZ0001749",
  "delivery_address": "123 Fake Drive",
  "delivery_suburb": "Sydney",
  "delivery_postcode": "2000",
  "delivery_state": "NSW",
  "delivery_country_code": "AU",
  "delivery_latitude": -33.77,
  "delivery_longitude": 150.91,
  "merchant_url": "myshopify.storename.com",
  "status_history": [
    {
      "status": "completed",
      "time": "2016-04-26T19:36:32.000Z"
    },
    {
      "status": "with_driver",
      "time": "2016-04-26T18:36:32.000Z"
    },
    {
      "status": "in_transit",
      "time": "2016-04-26T17:36:32.000Z"
    },
    {
      "status": "ready_for_pickup",
      "time": "2016-04-26T16:36:11.000Z"
    },
    {
      "status": "despatch_in_progress",
      "time": "2016-04-26T16:27:35.000Z"
    },
    {
      "status": "order_placed",
      "time": "2016-04-26T16:25:04.000Z"
    }
  ],
  "products": [
    {
      "quantity": 1,
      "sku": "EWPE123123",
      "title": "Super awesome red tshirt",
      "product_line_id": "1234"
    },
    {
      "quantity": 7,
      "sku": "EWPE123123",
      "title": "Super awesome blue tshirt",
      "product_line_id": "1235"
    }
  ]
}';
const headers = {
  'Content-Type':'application/json'
};

fetch('https://app.staging.shippit.com/api/3/webhook',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

Ruby:

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json'
}

result = RestClient.post 'https://app.staging.shippit.com/api/3/webhook',
  params: {
  }, headers: headers

p JSON.parse(result)

Python:

import requests
headers = {
  'Content-Type': 'application/json'
}

r = requests.post('https://app.staging.shippit.com/api/3/webhook', headers = headers)

print(r.json())

PHP:

<?php

require 'vendor/autoload.php';

$headers = array(
    'Content-Type' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','https://app.staging.shippit.com/api/3/webhook', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

Java:

URL obj = new URL("https://app.staging.shippit.com/api/3/webhook");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

Golang:

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "https://app.staging.shippit.com/api/3/webhook", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}