Search code examples
javaeclipseeclipse-scoutshippo

Receiving shipping rates from Shippo - Eclipse


After a bit of work I was able to finally get Shippo to connect to my eclipse IDE. However after trying their examples I realized the way you get rates from their code is not the same. After changing getRates to getRateList the return on my rate list is null. Even printing out the shipment return isn't giving me any USPS rates only DHL, UPS, and LPS, all of which aren't even rates, but print out different problems on why they can't give me a rate. I am wondering why I cant get any rates back even with Shippo's example (yes I tried addresses local to me). It only has to be USPS because I don't want to ship through other service providers but I am asking whether the issue is with my code, whether I am missing something or whether something needs to be changed in my Shippo account. I have read all their documentation and looked up this question a lot and nobody seems to have the same problem I have. I also tried this on both the test token and the live token given by my shippo account. Also in my carrier accounts I set USPS to allow for test labels using my test API.

Here is my code in my Eclipse Scout IDE:

    // TEST API NO CHARGE
    Shippo.setApiKey("shippo_test_XXXXXXXXXXXXXXXXXXXXXXXXXX");
    // Shippo.setDEBUG(true);
    Map<String, Object> toAddressMap = new HashMap<String, Object>();
    toAddressMap.put("name", "Mr Hippo");
    toAddressMap.put("company", "Shippo");
    toAddressMap.put("street1", "215 Clayton St.");
    toAddressMap.put("city", "San Francisco");
    toAddressMap.put("state", "CA");
    toAddressMap.put("zip", "94117");
    toAddressMap.put("country", "US");
    toAddressMap.put("phone", "+1 555 341 9393");
    toAddressMap.put("email", "[email protected]");
    // toAddressMap.put("is_residential", true);

    // from address
    Map<String, Object> fromAddressMap = new HashMap<String, Object>();
    fromAddressMap.put("name", "Ms Hippo");
    fromAddressMap.put("company", "San Diego Zoo");
    fromAddressMap.put("street1", "2920 Zoo Drive");
    fromAddressMap.put("city", "San Diego");
    fromAddressMap.put("state", "CA");
    fromAddressMap.put("zip", "92101");
    fromAddressMap.put("country", "US");
    fromAddressMap.put("email", "[email protected]");
    fromAddressMap.put("phone", "+1 619 231 1515");
    fromAddressMap.put("metadata", "Customer ID 123456");
    // fromAddressMap.put("is_residential", true);

    // parcel
    Map<String, Object> parcelMap = new HashMap<String, Object>();
    parcelMap.put("length", "5");
    parcelMap.put("width", "5");
    parcelMap.put("height", "5");
    parcelMap.put("distance_unit", "in");
    parcelMap.put("weight", "2");
    parcelMap.put("mass_unit", "lb");
    List<Map<String, Object>> parcels = new ArrayList<Map<String, Object>>();
    parcels.add(parcelMap);

    Map<String, Object> shipmentMap = new HashMap<String, Object>();
    shipmentMap.put("address_to", toAddressMap);
    shipmentMap.put("address_from", fromAddressMap);
    shipmentMap.put("parcels", parcels);
    shipmentMap.put("async", false);

    try {
        Shipment shipment = Shipment.create(shipmentMap);
        System.out.println(shipment);

    } catch (AuthenticationException | InvalidRequestException | APIConnectionException | APIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

After running my code here is the JSON return I get back:

 "object_state": null,
 "object_status": null,
 "object_purpose": null,
 "object_id": "b4c380bbe17d4b0d9a468e91ddc247a3",
 "object_owner": "[email protected]",
 "object_created": "2022-03-20T09:19:28.505Z",
 "object_updated": "2022-03-20T09:19:28.649Z",
 "address_from": {
   "object_id": "311925ff01fe4514b9229d9145227a09",
   "is_complete": true,
   "name": "Ms Hippo",
   "company": "San Diego Zoo",
   "street_no": "",
   "street1": "2920 Zoo Drive",
   "validation_results": {},
   "street2": "",
   "street3": "",
   "city": "San Diego",
   "state": "CA",
   "zip": "92101",
   "country": "US",
   "phone": "0016192311515",
   "email": "[email protected]",
   "is_residential": null,
   "test": true
 },
 "address_to": {
   "object_id": "c0fe7b3cc2684fa9bef7177259aba099",
   "is_complete": true,
   "name": "Mr Hippo",
   "company": "Shippo",
   "street_no": "",
   "street1": "215 Clayton St.",
   "validation_results": {},
   "street2": "",
   "street3": "",
   "city": "San Francisco",
   "state": "CA",
   "zip": "94117",
   "country": "US",
   "phone": "0015553419393",
   "email": "[email protected]",
   "is_residential": null,
   "test": true
 },
 "address_return": {
   "object_id": "311925ff01fe4514b9229d9145227a09",
   "is_complete": true,
   "name": "Ms Hippo",
   "company": "San Diego Zoo",
   "street_no": "",
   "street1": "2920 Zoo Drive",
   "validation_results": {},
   "street2": "",
   "street3": "",
   "city": "San Diego",
   "state": "CA",
   "zip": "92101",
   "country": "US",
   "phone": "0016192311515",
   "email": "[email protected]",
   "is_residential": null,
   "test": true
 },
 "parcel": null,
 "submission_type": null,
 "submission_date": null,
 "insurance_amount": null,
 "insurance_currency": null,
 "extra": {},
 "customs_declaration": null,
 "reference_1": null,
 "reference_2": null,
 "rates_url": null,
 "metadata": "",
 "messages": [
   {
  "source": "UPS",
  "code": "110920",
  "text": "RatedShipmentAlert: Ship To Address Classification is changed from Commercial to Residential"
},
{
  "source": "UPS",
  "code": "110971",
  "text": "RatedShipmentAlert: Your invoice may vary from the displayed reference rates"
},
{
  "source": "ShippoCommon",
  "code": "",
  "text": "Shipment origin or destination state is out of the service area for LSO."
},
{
  "source": "DHLExpress",
  "code": "",
  "text": "Shippo\u0027s DHL Express master account doesn\u0027t support shipments to inside of the US"
}
 ],
 "rates_list": null
 } 

Solution

  • Reviewing the results set sent back in JSON and pasting them in a JSON to string converter showed me that I was receiving rates even though I couldn't actually do anything with them. Updating Maven to 3.1.0 allowed me to use the same code and get rates back.