ericcj/amz_sp_api

Vendor Direct Fulfillment Shipment Api Model Issue

WebDeverDan opened this issue · 4 comments

Greetings! I'm working on a project and am using this gem, which is awesome! I've had excellent luck with it so far, but am running into a snag with this particular model. According to our contact at Amazon, we should be using the vendor-direct-fulfillment-shipping-api (namely the submit shipping confirmations, which uses this endpoint: /vendor/directFulfillment/shipping/2021-12-28/shipmentConfirmations). The only model that I've been able to find that is even close to this is the vendor-shipments-api-model, which uses the endpoint vendor/shipping/v1/shipmentConfirmations.

From my deep dive into this gem, is it possible that the 1021-12-28 model I'm looking for doesn't exist? According to the amzn selling partner api documentation here: https://github.com/amzn/selling-partner-api-models/blob/main/models/vendor-direct-fulfillment-shipping-api-model/vendorDirectFulfillmentShipping_2021-12-28.json, it looks like it should be there(maybe not here though). Below is my code, which is currently returning a 403 error (using the same configuration for the GetOrders and Acknowledgement calls which worked great). I've formatted the call according to the documentation for the gem model documentation, which seems to differ a bit from the overall readme example structure. Any insight would be very helpful and appreciated. Pardon the below formatting... Thanks!

`require 'aws-sdk-core'
require 'amz_sp_api'
require 'vendor-shipments-api-model'

module VENDOR_CENTRAL
module V1
class Shipping
class << self

    AmzSpApi.configure do |config|
      config.refresh_token = XX
      config.client_id = XX
      config.client_secret = XX
      config.credentials_provider = Aws::STS::Client.new(
            region: AmzSpApi::SpConfiguration::AWS_REGION_MAP['na'],
            access_key_id: XX,
            secret_access_key: XX,
          ).assume_role(role_arn: XX, role_session_name: SecureRandom.uuid)
      config.region = 'na'
      config.timeout = 30 # seconds
    end

    def create_shipment(shipment, order, line_items, notification)
      api_instance = AmzSpApi::VendorShipmentsApiModel::VendorShippingApi.new(AmzSpApi::SpApiClient.new)
      body = AmzSpApi::VendorShipmentsApiModel::SubmitShipmentConfirmationsRequest.new
      details = order.details["orderDetails"]
      items = []
      details["items"].each do |item|
        item_sequence_number = item["itemSequenceNumber"]
        shipped_quantity = item["orderedQuantity"]["amount"]
        items << {
          "itemSequenceNumber": item_sequence_number,
          "shippedQuantity": shipped_quantity 
                 }
        end
      opts = { 
                "shipmentConfirmation":[
                {
                "shipmentIentifier": "#{notification.included["mwwondemand_orders"][0]["id"]}",
                "shipmentConfirmationType": "original",
                "purchaseOrderNumber": "#{order.po_number}",
                "shipmentConfirmationDate": DateTime.now,
                "shipmentDetails": {
                  "shippedDate": DateTime.now,
                  "shipmentStatus": "SHIPPED"
                  },
                "sellingParty": {
                  "partyId": "#{details["sellingParty"]["partyId"]}"
                },
                "sellingPartner": {
                  "partyId": "#{details["shipFromParty"]["partyId"]}"
                },
                "items": items 
                  }
                ]
            }
      begin
        result = api_instance.submit_shipment_confirmations(body, opts)
        p api_instance
        p result
      rescue AmzSpApi::VendorShipmentsApiModel::ApiError => e
        puts "Exception when calling VendorShippingApi->submit_shipment_confirmations: #{e}"
      end
    end


  end
end

end
end
`

How would the structure for my response vary from how I originally had it? I'm not too experienced a developer, so any help would be awesome. Thanks!

i'm not sure your edited version looks vaguely correct but you'd have to read through their docs

@ericcj Are the docs that are at that link that you sent not the gem docs? The instance method looks nearly identical to the v1 code, so I'm just having a hard time understanding what that means. Any other help would be appreciated. Thanks so much!