lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
MIT License
307 stars 130 forks source link

Put Transport Content #33

Closed jmcmains closed 9 years ago

jmcmains commented 9 years ago

Running into another bug and I'm wondering if this is the issue:

code looks like this: def put_transport_content(shipment_id, is_partnered, shipment_type, transport_details) operation('PutTransportContent') .add( 'ShipmentId' => shipment_id, 'IsPartnered' => is_partnered, 'ShipmentType' => shipment_type, 'TransportDetails' => transport_details ) run end

other similar functions include: def put_transport_content(shipment_id, is_partnered, shipment_type, transport_details) operation('PutTransportContent') .add(opts.update( 'ShipmentId' => shipment_id, 'IsPartnered' => is_partnered, 'ShipmentType' => shipment_type, 'TransportDetails' => transport_details )) .structure!('PackageList', 'member') run end

no idea what the extra code does, but similar functions have it and this seems to be missing it. been getting another "Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request)" and everything from what I can tell everything I enter should work (I even did a get_transport_content and copied the data with no luck). Thoughts?

hakanensari commented 9 years ago

Yes, it does sound like the internals of TransportDetails are not built correctly.

What does your request look like? What does Amazon's response state? You can view latter by rescuing the error and inspecting the embedded response object.

jmcmains commented 9 years ago

request: TransportDetails is built like this:

package_list=shipment.packages.map { |b| 
    {
        "Weight" => {"Unit" => "pounds", "Value" => b.weight.to_i},
        "Dimensions" => {"Unit" => "IN", "Height" => b.height, "Width" => b.width, "Length" => b.length}
    }
}

transport_details = { 
    "PartneredSmallParcelData" => {
        "PackageList" => package_list
    }
}

Then the request is:

transport_content=fulfillment_inbound_shipment_client.put_transport_content(shipment_id, true, 'SP', transport_details)

response I get from the error is:

{"Type"=>"Sender", "Code"=>"MalformedInput", "Message"=>"Unexpected complex element termination"} 

but i receive the same error when I manually enter the shipment info in seller central, and then run:

transport_content_manual=fulfillment_inbound_shipment_client.get_transport_content(shipment_id)
transport_content=fulfillment_inbound_shipment_client.put_transport_content(shipment_id, true, 'SP', transport_content_manual["TransportContent"]["TransportDetails"]))

Thanks for your help!

hakanensari commented 9 years ago

@jmcmains, could you please confirm the master branch fixes this issue? I don't have anything in production using this part of the API.

jmcmains commented 9 years ago

seems to be working! Awesome! Thanks for figuring it out!