Estimated delivery date code examples

Code examples for the estimated delivery dates API.

Bash

# You can also use wget
curl -X POST https://app.shippit.com/api/v3/estimated_delivery_dates \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: API_KEY' \
  -d '{
    "from_postcode": "2000",
    "to_postcode": "3000",
    "service_levels": ["standard", "express", "on_demand"]
  }'

HTTP

POST /api/v3/estimated_delivery_dates HTTP/1.1
Host: app.shippit.com
Content-Type: application/json
Accept: application/json
Authorization: API_KEY

{
  "from_postcode": "2000",
  "to_postcode": "3000",
  "service_levels": ["standard", "express", "on_demand"]
}

Javascript

const inputBody = {
  from_postcode: "2000",
  to_postcode: "3000",
  couriers: ["CouriersPlease", "eParcelExpress"],
  service_levels: ["standard", "express", "on_demand"],
  preparation_time: "00:01:05",
  pickup_days_per_courier: [
    {
      courier: "eParcelExpress",
      pickup_days: ["monday", "tuesday"],
      pickup_time: "16:00",
    },
  ],
  store_operating_hours: [
    {
      day: "monday",
      open_time: "09:00",
      close_time: "17:00",
    },
  ],
};

const headers = {
  "Content-Type": "application/json",
  Accept: "application/json",
  Authorization: "API_KEY",
};

fetch("https://app.shippit.com/api/v3/estimated_delivery_dates", {
  method: "POST",
  body: JSON.stringify(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',
  'Accept' => 'application/json',
  'Authorization' => 'API_KEY'
}

payload = {
  from_postcode: '2000',
  to_postcode: '3000',
  service_levels: ['standard', 'express', 'on_demand'],
  preparation_time: '00:01:05'
}

result = RestClient.post 'https://app.shippit.com/api/v3/estimated_delivery_dates',
  payload.to_json, headers

p JSON.parse(result)

Python

import requests
import json

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'API_KEY'
}

payload = {
  "from_postcode": "2000",
  "to_postcode": "3000",
  "service_levels": ["standard", "express", "on_demand"],
  "preparation_time": "00:01:05"
}

r = requests.post('https://app.shippit.com/api/v3/estimated_delivery_dates',
                  headers=headers,
                  data=json.dumps(payload))

print(r.json())

PHP

<?php

require 'vendor/autoload.php';

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

$client = new \GuzzleHttp\Client();

$request_body = array(
    'from_postcode' => '2000',
    'to_postcode' => '3000',
    'service_levels' => array('standard', 'express', 'on_demand'),
    'preparation_time' => '00:01:05'
);

try {
    $response = $client->request('POST', 'https://app.shippit.com/api/v3/estimated_delivery_dates', 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

import java.net.URL;
import java.net.HttpURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class EstimatedDeliveryDates {
    public static void main(String[] args) throws Exception {
        URL obj = new URL("https://app.shippit.com/api/v3/estimated_delivery_dates");
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("Accept", "application/json");
        con.setRequestProperty("Authorization", "API_KEY");

        String jsonInputString = "{\"from_postcode\": \"2000\", \"to_postcode\": \"3000\", \"service_levels\": [\"standard\", \"express\", \"on_demand\"]}";

        con.setDoOutput(true);
        try(OutputStream os = con.getOutputStream()) {
            byte[] input = jsonInputString.getBytes("utf-8");
            os.write(input, 0, input.length);
        }

        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());
    }
}

Go

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "io/ioutil"
)

type EstimateRequest struct {
    FromPostcode  string   `json:"from_postcode"`
    ToPostcode    string   `json:"to_postcode"`
    ServiceLevels []string `json:"service_levels"`
    PreparationTime string `json:"preparation_time,omitempty"`
}

func main() {
    url := "https://app.shippit.com/api/v3/estimated_delivery_dates"

    payload := EstimateRequest{
        FromPostcode:  "2000",
        ToPostcode:    "3000",
        ServiceLevels: []string{"standard", "express", "on_demand"},
        PreparationTime: "00:01:05",
    }

    jsonData, err := json.Marshal(payload)
    if err != nil {
        panic(err)
    }

    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    if err != nil {
        panic(err)
    }

    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Accept", "application/json")
    req.Header.Set("Authorization", "API_KEY")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(body))
}