demonchand
demonchand

Reputation: 11451

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 quickly?

Thanks

Upvotes: 1

Views: 1906

Answers (2)

peterhartman
peterhartman

Reputation: 171

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

Upvotes: 6

B00MER
B00MER

Reputation: 5491

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

Upvotes: 1

Related Questions