How to use the savon gem with Magento SOAP API
How do I access the Magento SOAP API using the savon gem. Are there any examples that I can use to get going q开发者_如何学Gouickly?
Thanks
Try this to get you started:
require 'rubygems'
require 'savon'
client = Savon::Client.new do
wsdl.document = "http://your.server.here/index.php/api/?wsdl"
end
response = client.request :login do
soap.body = { :username => 'soapuser', :apiKey => 'myapikey' }
end
if response.success? == false
puts "login failed"
System.exit(0)
end
session = response[:login_response][:login_return];
response = client.request :call do
soap.body = {:session => session,:method => 'catalog_product.list' }
end
# fetching all products
if response.success?
# listing found products
response[:call_response][:call_return][:item].each do |product|
puts "-------------------------------------------"
product = product[:item]
product.each do |pkey|
puts "#{pkey[:key]} -> #{pkey[:value]}"
end
end
end
#logging out
response = client.request :endSession do
soap.body = {:session => session}
end
puts response.to_hash
C# Example of using Magento's API:
The same applies to any other language including ruby. Obviously the syntax will differ and i'm assuming you know the Savon syntax already.
You may also want to checkout: https://github.com/timmatheson/Magento#readme
精彩评论