skeniver
skeniver

Reputation: 2647

Ruby Savon set SOAP header element

I am trying to add an API Key element to a SOAP header using Savon, but am fighting a losing battle. I am fairly new to Ruby and the little I do know is self taught. According their API docs this is what I need to add: This ProductServe function will return (SOAP-Header) the authentication element and this has to be sent with every single request.

Parameters

Required  Name     Type    Description                              Min Occurs Max Occurs
No        sToken   string  Unique token to identify visitor.        0          1
Yes       sApiKey  string  User specific key to authenticate user.  1          1

http://wiki.affiliatewindow.com/index.php/UserAuthentication

I haven't managed to find anything that resembles what I want to do and this is the code I have tried:

endpoint = "http://v3.core.com.productserve.com/ProductServeService.wsdl"
client = Savon.client

response = client.request :urn, "getCategory" do
  soap.endpoint = endpoint
  soap.header = {
    "urn:sApiKey" => "xxxx"
  }
end

Any help would be greatly appreciated!

Upvotes: 1

Views: 2047

Answers (1)

LazyMonkey
LazyMonkey

Reputation: 527

Looks like you need to configure your Savon client:

client = Savon::Client.new do
  wsdl.document = endpoint
  wsdl.element_form_default = :unqualified
end

I made those changes and the rest of your code returned a valid SOAP response.

Shamelessly cribbed from this question

Upvotes: 1

Related Questions