0

In a Rails 4 app using Shippo for shipping, I'm passing the following hash into Shippo::Shipment.create(shippo_params), as per the API docs:

{
:object_purpose => "PURCHASE",
         :async => false,
    :address_to => {
    "object_purpose" => "PURCHASE",
              "name" => "Test Guy",
           "street1" => "5000 Test St",
           "street2" => "",
              "city" => "New Orleans",
             "state" => "LA",
               "zip" => "70115",
           "country" => "US"
},
  :address_from => {
    "object_purpose" => "PURCHASE",
           "company" => "MyCompany",
           "street1" => "1305 Business Lane",
           "street2" => "Suite O",
              "city" => "New Orleans",
             "state" => "LA",
               "zip" => "70123",
           "country" => "US",
             "phone" => "+1 999 999 9999",
},
        :parcel => {
           "length" => 5,
            "width" => 5,
           "height" => 5,
    "distance_unit" => :in,
           "weight" => 1,
        "mass_unit" => :lb
}

}

I then receive the error:

Shippo::Exceptions::APIServerError: Unable to read data received back from the server.  

If I use the following params hash as referenced in the API, it works:

params   = { object_purpose: 'PURCHASE',
                    async:          false,
                    address_from:   {
                      object_purpose: 'PURCHASE',
                      name:           'Mr Hippo',
                      company:        'Shippo',
                      street1:        '215 Clayton St.',
                      street2:        '',
                      city:           'San Francisco',
                      state:          'CA',
                      zip:            '94117',
                      country:        'US',
                      phone:          '+1 555 341 9393',
                      email:          'support@goshippo.com' },
                    address_to:     {
                      object_purpose: 'PURCHASE',
                      name:           'Mrs Hippo"',
                      company:        'San Diego Zoo',
                      street1:        '2920 Zoo Drive',
                      city:           'San Diego',
                      state:          'CA',
                      zip:            '92101',
                      country:        'US',
                      phone:          '+1 555 341 9393',
                      email:          'hippo@goshippo.com' },
                    parcel:         {
                      length:        5,
                      width:         2,
                      height:        5,
                      distance_unit: :in,
                      weight:        2,
                      mass_unit:     :lb }
                    }

There are subtle differences in the two, upon calling inspect, the former has some escaped quotes in the keys, and the other doesn't, but I don't know why this would matter (or why it's being set that way).

Can anyone tell me what the difference is and why Shippo is returning this error?

rcd
  • 1,348
  • 1
  • 14
  • 27

1 Answers1

2

There are two issues:

  1. In your request the Address objects don't contain all required fields. Here's a working request with your data - I added email values to both addresses and a name value to the address_from object: https://gist.github.com/simonkreuz/2da33c20d4015b0bc64079078db62ddc
  2. Shippo's Ruby wrapper doesn't parse the returned API error message correctly. The API is actually returning an error indicating that the Address objects didn't contain all required fields. I've filed a ticket with the engineering team at Shippo here https://github.com/goshippo/shippo-ruby-client/issues/22.
Simon Kreuz
  • 575
  • 3
  • 8
  • You were right; I wasn't including an email on the address_to because it isn't always available during a guest checkout. I'll have to rework the app; it's a shame that isn't optional. Thanks for your help. – rcd Sep 19 '16 at 15:21
  • @rcd thanks for the feedback, glad to hear it's working now. We will change the email to be optional in a future API version - you can join this Google Group to get updates https://groups.google.com/forum/#!forum/shippo-api-announce. – Simon Kreuz Sep 19 '16 at 23:03