Let me preface this by saying that I am still pretty new to SOAP and how things should work. I'm working with the Vertical Response API.
I'm having trouble getting suds to construct the xml correctly for a request. Here is some code:
from suds.client import Client
url = 'https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl'
client = Client(url)
vr = client.service
...
test_list = (
(
{
'name' : 'email_address',
'value' : login['username'],
},
{
'name' : 'First_Name',
'value' : 'VR_User',
}
),
(
{
'name' : 'email_address',
'value' : '
[email protected]',
},
{
'name' : 'First_Name',
'value' : login['username'],
},
),
)
#
sid and cid are correctly retrieved prior to this point
print "Sending test message..."
vr.sendEmailCampaignTest({
'session_id' :
sid,
'campaign_id' : cid,
'recipients' : test_list,
})
In this context login['username'] is just an email address.
That code raises this error:
suds.WebFault: Server raised fault: 'Application failed during request deserialization: Too many elements in array. 4 instead of claimed 2 (2)
Here is the the definition of sendEmailCampaignTest:
http://developers.verticalresponse.com/api/soap/methods/campaigns/sendemailcampaigntest/
Here is the xml that logging outputs (I removed the session_id and list_id for display here):
DEBUG:suds.client:headers = {'SOAPAction': u'"VR/API/1_0#sendEmailCampaignTest"', 'Content-Type': 'text/xml; charset=utf-8'}
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://api.verticalresponse.com/1.0/VRAPI.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="VR/API/1_0" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns0:Body>
<ns4:sendEmailCampaignTest>
<args xsi:type="ns3:sendEmailCampaignTestArgs">
<session_id xsi:type="ns1:string">redacted</session_id>
<campaign_id xsi:type="ns1:int">redacted</campaign_id>
<recipients xsi:type="ns3:ArrayOfNVDictionary" ns2:arrayType="ns3:NVDictionary[2]">
<item>
<name xsi:type="ns1:string">email_address</name>
<value xsi:type="ns1:string">
[email protected]</value>
</item>
<item>
<name xsi:type="ns1:string">First_Name</name>
<value xsi:type="ns1:string">VR_User</value>
</item>
<item>
<name xsi:type="ns1:string">email_address</name>
<value xsi:type="ns1:string">
[email protected]</value>
</item>
<item>
<name xsi:type="ns1:string">First_Name</name>
<value xsi:type="ns1:string">
[email protected]</value>
</item>
</recipients>
</args>
</ns4:sendEmailCampaignTest>
</ns0:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Application failed during request deserialization: Too many elements in array. 4 instead of claimed 2 (2)
</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
a ruby script (provided by Vertical Response) that does the same things as the script I am working on in python outputs the following xml (I removed the session_id and list_id):
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:sendEmailCampaignTest xmlns:n1="VR/API/1_0"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<args xmlns:n2="http://api.verticalresponse.com/1.0/VRAPI.xsd"
xsi:type="n2:sendEmailCampaignTestArgs">
<session_id xsi:type="xsd:string">redacted</session_id>
<campaign_id xsi:type="xsd:int">redacted</campaign_id>
<recipients xmlns:n3="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="n3:Array"
n3:arrayType="n2:NVDictionary[2]">
<item xsi:type="n3:Array"
n3:arrayType="n2:NVPair[2]">
<item>
<name xsi:type="xsd:string">email_address</name>
<value href="#id9496430"></value>
</item>
<item>
<name xsi:type="xsd:string">First_Name</name>
<value xsi:type="xsd:string">VR_User</value>
</item>
</item>
<item xsi:type="n3:Array"
n3:arrayType="n2:NVPair[2]">
<item>
<name xsi:type="xsd:string">email_address</name>
<value xsi:type="xsd:string">
[email protected]</value>
</item>
<item>
<name xsi:type="xsd:string">First_Name</name>
<value href="#id9496430"></value>
</item>
</item>
</recipients>
</args>
</n1:sendEmailCampaignTest>
<value id="id9496430"
xsi:type="xsd:string"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
[email protected]</value>
</env:Body>
</env:Envelope>
I understand that the error is in the construction of recipients. It should contain two items, each that contain two items but my python script using suds is setting it up to contain four unnested items. So my question is how can I get suds to correctly construct the xml?