Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Array Elements for Savon 2 (SOAP)

I'm trying to write code in Ruby with the Savon gem (v2) that fetches account information from a SOAP api, but I'm having an issue with passing an Array.

CampaignIds is supposed to be an array of integers.

Here is my code:

client = Savon.client(wsdl: "https://api7secure.publicaster.com/Pub7APIV1/Campaign.svc?singleWsdl")

message = {
  "EncryptedAccountID" => api_key,
  "APIPassword" => api_password,
  "CampaignIds" => [3,4],
  "StartDate" => yesterday,
  "EndDate" => yesterday,
  "IncludeTests" => false
}

client.call(:get_comparative_report_details_data, message: message)

which produces the following request:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:tns="http://BlueSkyFactory.Publicaster7.Public.API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Body>
      <tns:GetComparativeReportDetailsData>
         <tns:EncryptedAccountID>*****</tns:EncryptedAccountID>
         <tns:APIPassword>*****</tns:APIPassword>
         <tns:CampaignIds>3</tns:CampaignIds>
         <tns:CampaignIds>4</tns:CampaignIds>
         <tns:StartDate>2014-01-06</tns:StartDate>
         <tns:EndDate>2014-01-06</tns:EndDate>
         <tns:IncludeTests>false</tns:IncludeTests>
      </tns:GetComparativeReportDetailsData>
   </env:Body>
</env:Envelope>

whereas, if I play around in SOUP UI, the request should look like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blu="http://BlueSkyFactory.Publicaster7.Public.API" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
   <soapenv:Header/>
   <soapenv:Body>
      <blu:GetComparativeReportData>
         <blu:EncryptedAccountID>*****</blu:EncryptedAccountID>
         <blu:APIPassword>*****</blu:APIPassword>
         <blu:CampaignIds>
            <arr:int>3</arr:int>
            <arr:int>4</arr:int>
         </blu:CampaignIds>
         <blu:StartDate>2014-01-06T16:21:47-05:00</blu:StartDate>
         <blu:EndDate>2014-01-07T16:21:47-05:00</blu:EndDate>
         <blu:IncludeTests>false</blu:IncludeTests>
      </blu:GetComparativeReportData>
   </soapenv:Body>
</soapenv:Envelope>

Any Ideas?

like image 618
Sam Lehman Avatar asked Jan 07 '14 21:01

Sam Lehman


1 Answers

You can try this syntax :

message = {
  ...
  "CampaignIds" => {"int" => [3,4]},
  ...
}

That'll produce this output :

<CampaignIds>
  <int>3</int>
  <int>4</int>
</CampaignIds>

Hope this helps.

like image 56
Yann VERY Avatar answered Oct 01 '22 00:10

Yann VERY