How to add a new object with foam?

I am trying to use foam, but still have not been able to figure it out.

This should be the raw soapy message 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>test@test.com</email>
             </member>
         </api:insertOrUpdateMemberByObj>
     </soapenv:Body>
</soapenv:Envelope>

Therefore, I use foaming to create a member object:

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

gives:

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

How can I add a β€œrecord”?

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 really need:

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

How do I achieve this?

+3
source share
4 answers

On top of my head (all the foam work is working now)

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

It depends on the WSDL that defines your SOAP connection, but attributesshould also be a structure defined in the WSDL.

0
source

factory:

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

, , "":

>>> 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'
>>>
0

, WSDL.

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

, WSDL.

0
source

Source: https://habr.com/ru/post/1747629/


All Articles