Sample code for 30+ languages & platforms
Java

Shippo List All Orders

See more Shippo Examples

Demonstrates how to list all orders created by sending a GET request to the orders endpoint.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // Implements the following CURL command:

        // curl https://api.goshippo.com/orders/ \
        //     -H "Authorization: ShippoToken <API_Token>"

        http.setRequestHeader("Authorization", "ShippoToken <API_Token>");

        StringBuilder sbResponseBody = new StringBuilder();
        try {
            http.quickGetSb("https://api.goshippo.com/orders/", sbResponseBody);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject jResp = new JsonObject();
        jResp.loadSb(sbResponseBody);
        jResp.setEmitCompact(false);

        System.out.println("Response Body:");
        System.out.println(jResp.emit());

        int respStatusCode = http.getLastStatus();
        System.out.println("Response Status Code = " + respStatusCode);
        if (respStatusCode >= 400) {
            System.out.println("Response Header:");
            System.out.println(http.getLastHeader());
            System.out.println("Failed.");
            return;
        }

        // Sample JSON response:
        // (Sample code for parsing the JSON response is shown below)

        // {
        //   "count": 1382,
        //   "next": "https://api.goshippo.com/orders/?page=2",
        //   "previous": null,
        //   "results": [
        //     {
        //       "object_id": "4f2bc588e4e5446cb3f9fdb7cd5e190b",
        //       "object_owner": "shippotle@goshippo.com",
        //       "order_number": "#1068",
        //       "order_status": "PAID",
        //       "placed_at": "2016-09-23T01:28:12Z",
        //       "to_address": {
        //         "object_created": "2016-09-23T01:38:56Z",
        //         "object_updated": "2016-09-23T01:38:56Z",
        //         "object_id": "d799c2679e644279b59fe661ac8fa488",
        //         "object_owner": "shippotle@goshippo.com",
        //         "is_complete": true,
        //         "validation_results": {},
        //         "name": "Mr Hippo",
        //         "company": "Shippo",
        //         "street1": "215 Clayton St.",
        //         "street2": "",
        //         "city": "San Francisco",
        //         "state": "CA",
        //         "zip": "94117",
        //         "country": "US",
        //         "phone": "15553419393",
        //         "email": "shippotle@goshippo.com",
        //         "is_residential": null,
        //         "metadata": ""
        //       },
        //       "from_address": null,
        //       "line_items": [
        //         {
        //           "object_id": "abf7d5675d744b6ea9fdb6f796b28f28",
        //           "title": "Hippo Magazines",
        //           "variant_title": "",
        //           "sku": "HM-123",
        //           "quantity": 1,
        //           "total_price": "12.10",
        //           "currency": "USD",
        //           "weight": "0.40",
        //           "weight_unit": "lb",
        //           "manufacture_country": null,
        //           "max_ship_time": null,
        //           "max_delivery_time": null,
        //           "description": null
        //         }
        //       ],
        //       "shipping_cost": "12.83",
        //       "shipping_cost_currency": "USD",
        //       "shipping_method": "USPS First Class Package",
        //       "shop_app": "Shippo",
        //       "subtotal_price": "12.10",
        //       "total_price": "24.93",
        //       "total_tax": "0.00",
        //       "currency": "USD",
        //       "transactions": [
        //       ],
        //       "weight": "0.40",
        //       "weight_unit": "lb",
        //       "notes": null
        //     },
        //     ...
        //   ]
        // }

        // Sample code for parsing the JSON response...
        // Use the following online tool to generate parsing code from sample JSON:
        // Generate Parsing Code from JSON

        int intVal = 0;
        int j = 0;
        int count_j = 0;
        String object_id = "";
        String title = "";
        String variant_title = "";
        String sku = "";
        int quantity = 0;
        String total_price = "";
        String currency = "";
        String weight = "";
        String weight_unit = "";
        String manufacture_country = "";
        String max_ship_time = "";
        String max_delivery_time = "";
        String description = "";

        int count = jResp.intOf("count");
        String next = jResp.stringOf("next");
        String previous = jResp.stringOf("previous");
        int i = 0;
        int count_i = jResp.sizeOfArray("results");
        while (i < count_i) {
            jResp.setI(i);
            intVal = jResp.intOf("results[i]");
            j = 0;
            count_j = jResp.sizeOfArray("results[i].line_items");
            while (j < count_j) {
                jResp.setJ(j);
                object_id = jResp.stringOf("results[i].line_items[j].object_id");
                title = jResp.stringOf("results[i].line_items[j].title");
                variant_title = jResp.stringOf("results[i].line_items[j].variant_title");
                sku = jResp.stringOf("results[i].line_items[j].sku");
                quantity = jResp.intOf("results[i].line_items[j].quantity");
                total_price = jResp.stringOf("results[i].line_items[j].total_price");
                currency = jResp.stringOf("results[i].line_items[j].currency");
                weight = jResp.stringOf("results[i].line_items[j].weight");
                weight_unit = jResp.stringOf("results[i].line_items[j].weight_unit");
                manufacture_country = jResp.stringOf("results[i].line_items[j].manufacture_country");
                max_ship_time = jResp.stringOf("results[i].line_items[j].max_ship_time");
                max_delivery_time = jResp.stringOf("results[i].line_items[j].max_delivery_time");
                description = jResp.stringOf("results[i].line_items[j].description");
                j = j + 1;
            }

            j = 0;
            count_j = jResp.sizeOfArray("results[i].transactions");
            while (j < count_j) {
                jResp.setJ(j);
                j = j + 1;
            }

            i = i + 1;
        }
    }
}