ruby - 如何使用 Ruby Savon 为类别产品链接正确调用 Magento SOAP API?

标签 ruby magento soap savon

我正在尝试调用 catalog_product_link.list API 方法使用 Savon .但是,我一直收到错误 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'})}

是否有不同的格式来使其正常工作?

更新:如果我尝试删除类型参数,它会给出错误 Given invalid link type , 所以看起来它不喜欢关于多个参数的东西。

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

最佳答案

我能够使用 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 direction .

关于ruby - 如何使用 Ruby Savon 为类别产品链接正确调用 Magento SOAP API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14633904/

相关文章:

java - 使用 JAVA (MULE) 访问有效负载

Android:关于android webservice

ruby - 从 ruby 2.2.0 更新到 2.5

Magento 不会在 'save' 上保存值(value)

ruby - 为什么 Kernel#require 在 Ruby 中引发 LoadError?

magento - 如何在 Magento <meta name ="robots"content ="NOINDEX,FOLLOW"/> 中编辑单个页面

php - 在 Magento 中获取包含详细信息的所有类别的数组

java - 无法从 UPS Void wsdl 生成 java 文件 : void is a Java keyword

ruby-on-rails - 如何在 Ruby on Rails 网站上禁用显式堆栈跟踪

ruby-on-rails - 与 Rails 插件相比,Ruby gem 应该包含哪些内容?