Jerome
Jerome

Reputation: 67

How to add a new object with suds?

I'm trying to use suds but have so far been unsuccessful at figuring this out.

This is supposed to be the raw soap message that I need to achieve:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://api.service.apimember.soapservice.com/">
    <soapenv:Header/>
    <soapenv:Body>
        <api:insertOrUpdateMemberByObj>
        <token>t67GFCygjhkjyUy8y9hkjhlkjhuii</token>
             <member>
                 <dynContent>
                     <entry>
                         <key>FIRSTNAME</key>
                         <value>hhhhbbbbb</value>
                     </entry>
                 </dynContent>
                 <email>[email protected]</email>
             </member>
         </api:insertOrUpdateMemberByObj>
     </soapenv:Body>
</soapenv:Envelope>

So I use suds to create the member object:

member = client.factory.create('member')

produces:

(apiMember){
   attributes =
      (attributes){
         entry[] = <empty>
      }
 }

How exactly do I append an 'entry'?

I tried this:

member.attributes.entry.append({'key':'FIRSTNAME','value':'test'})

which produces this:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

However, what I actually need is:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            (entry) {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

How do I achieve this?

Upvotes: 3

Views: 9119

Answers (4)

eflauzo
eflauzo

Reputation: 11

you still need to create object with factory:

member = client.factory.create('member')
entry = client.factory.create('member.attributes.entry')
entry.key = 'FIRSTNAME';
entry.value = 'test';
member.attributes.entry.append(entry)

Upvotes: 1

chrisg
chrisg

Reputation: 41655

Try this, a similar thing worked using my WSDL.

member.attributes.entry = {'key':'FIRSTNAME','value':'test'}

As simon said, it does depend on your WSDL.

Upvotes: 0

Jerome
Jerome

Reputation: 1

This is what happens when i try to create "entry":

>>> member = client.factory.create('member')
>>> entry = client.factory.create('attributes')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\suds\client.py", line 231, in create
suds.TypeNotFound: Type not found: 'attributes'
>>>

Upvotes: 0

Simon Callan
Simon Callan

Reputation: 3130

Off the top of my head (all the suds stuff is at work at the moment)

member = client.factory.create('member')
entry = client.factory.create('attributes')
entry.key="FIRSTNAME"
entry.value="test"
member.attributes.entry.append(entry)

This does depend on the WSDL that defines your SOAP connection, but attributes should also be a structure defined in the WSDL.

Upvotes: 0

Related Questions