3

Savoncatalog_product_link.listを使用してAPIメソッドを呼び出そうとしています。しかし、私はエラーを受け取り続けます。Error cannot find parameter

これが私が使用しているものですが、私は呼び出しのいくつかのバリエーションを試しましたが、それでも正しく通過させることができません:

client = Savon.client(wsdl: 'http://localhost/index.php/api/soap/?wsdl')
response = client.call(:login){message(username: 'user', apiKey: 'key')}
session = response.body[:login_response][:login_return]

#These all do not work
client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :type => 'up_sell', :productId => '166')}
client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :type => 'up_sell', :product => '166')}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :args => {:type => 'up_sell', :product => '166'})}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :args => {:type => 'up_sell', :productId => '166'})}
client.call(:call){message(:sessionId => session, :resourcePath => 'catalog_product_link.list', :arguments => {:type => 'up_sell', :product => '166'})}

これを機能させるためにフォーマットする別の方法はありますか?

更新:typeパラメーターを削除しようとすると、エラーが発生Given invalid link typeするため、複数のパラメーターについては気に入らないようです。

response = client.call(:call){message(:session => session, :method => 'catalog_product_link.list', :product => '166')}
4

1 に答える 1

0

Builderを使用してこれを機能させることができました:

class ServiceRequest
  def initialize(session, type, product)
    @session = session
    @type = type
    @product = product
  end

  def to_s
    builder = Builder::XmlMarkup.new()
    builder.instruct!(:xml, encoding: "UTF-8")

    builder.tag!(
      "env:Envelope",
      "xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/",
      "xmlns:ns1" => "urn:Magento",
      "xmlns:ns2" => "http://xml.apache.org/xml-soap",
      "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", 
      "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
    ) do |envelope|
      envelope.tag!("env:Body") do |body|
        body.tag!("ns1:call") do |call|
          builder.sessionId(@session, "xsi:type" => "xsd:string")
          builder.resourcePath("catalog_product_link.list", "xsi:type" => "xsd:string")
          builder.args("xsi:type" => "ns2:Map") do |args|
            args.item do |item|
              item.key("type", "xsi:type" => "xsd:string")
              item.value(@type, "xsi:type" => "xsd:string")
            end
            args.item do |item|
              item.key("product", "xsi:type" => "xsd:string")
              item.value(@product, "xsi:type" => "xsd:string")
            end
          end
        end
      end
    end

    builder.target!
  end
end

client.call(:call, xml: ServiceRequest.new(session, 'up_sell', '166').to_s)

@rubiii の指示に感謝します。

于 2013-02-01T16:56:15.803 に答える