I've integrated Shippo with my Ruby on Rails Spree platform. Everything seems to be working great, except that when I go to create a transaction to print shipping labels, I get an error in the response.
Here's my response:
#<Transaction:0x3feee363470c[id=1b419434531e4b43b438c54b93e2a9f5]
{"object_state"=>"VALID", "status"=>"ERROR", "object_created"=>"2017-06-27T23:11:54.567Z", "object_updated"=>"2017-06-27T23:11:55.330Z", "object_id"=>"xxxx", "object_owner"=>"----@gmail.com", "test"=>true, "rate"=>{"object_id"=>"xxxx", "amount"=>"6.52", "currency"=>"USD", "amount_local"=>"6.52", "currency_local"=>"USD", "provider"=>"USPS", "servicelevel_name"=>"Priority Mail", "servicelevel_token"=>"usps_priority", "carrier_account"=>"xxxx"}, "tracking_number"=>"", "tracking_status"=>nil, "tracking_history"=>[], "tracking_url_provider"=>"", "label_url"=>"", "commercial_invoice_url"=>nil, "messages"=>[#<Hashie::Mash code="" source="USPS" text="Request failed. Please try again or contact Shippo support at support@goshippo.com.">], "order"=>nil, "metadata"=>"", "parcel"=>"xxxx"}->#<Shippo::API::ApiObject created=2017-06-27 23:11:54 UTC id="1b419434531e4b43b438c54b93e2a9f5" owner="xxxx@xxxx.com" state=#<Shippo::API::Category::State:0x007fddbca5a2e8 @name=:state, @value=:valid> updated=2017-06-27 23:11:55 UTC>
Here's the code used to create the label:
def self.createLabel(order_info)
shipping_info = order_info.shipping_address
stock_location = order_info.store.stock_location
address_from = {
:name => stock_location.name,
:company => order_info.store.name,
:street1 => stock_location.address1,
:street2 => stock_location.address2,
:city => stock_location.city,
:state => "#{Spree::State.find(stock_location.state_id)}",
:zip => stock_location.zipcode,
:country => "#{Spree::Country.find(stock_location.country_id)}",
:phone => stock_location.phone,
}
address_to = {
:name => "#{shipping_info.firstname} #{shipping_info.lastname}",
:company => shipping_info.company,
:street1 => shipping_info.address1,
:street2 => shipping_info.address2,
:city => shipping_info.city,
:state => "#{Spree::State.find(shipping_info.state_id)}",
:zip => shipping_info.zipcode,
:country => "#{Spree::Country.find(shipping_info.country_id)}",
:phone => shipping_info.phone,
:email => order_info.email
}
parcel = {
:length => getLength(order_info),
:width => getWidth(order_info),
:height => getHeight(order_info),
:distance_unit => :m,
:weight => getWeight(order_info),
:mass_unit => :lb
}
shipment = {
:address_from => address_from,
:address_to => address_to,
:parcels => parcel
}
#Shippo Carrier ids
@ups = Rails.application.secrets.ups_shippo_id
@usps = Rails.application.secrets.usps_shippo_id
transaction = Shippo::Transaction.create(
:shipment => shipment,
:carrier_account => "#{@usps}",
:servicelevel_token => "usps_priority",
:label_file_type => "PDF",
:async => false
)
end
Has anyone run into this issue before? I've looked at their documentation and cannot find any reason for a "status"=>"ERROR"
message, when the "object_state"=>"VALID"
.
I'm happy to post more code if needed. Thanks.
What I found with lots of trial and error, was that the products I was sending to Shippo actually exceeded the weight the shipping carrier would allow in a package. (This was because my database was a bunch of dummy data). Be sure to be setting your measurement units as well, here:
parcel = {
:length => getLength(order_info),
:width => getWidth(order_info),
:height => getHeight(order_info),
:distance_unit => :m,
:weight => getWeight(order_info),
:mass_unit => :lb
}
After changing the data in my database to have reasonable weights on the products, this error went away.