cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1694
Views
35
Helpful
2
Replies

Zeep Challenge!! How can you wash your Python JSON with SoapUI?

npetrele
Cisco Employee
Cisco Employee

SoapUI is probably the most useful and powerful way to test out SOAP operations when writing code for CUCM (such as AXL, Serviceability, among other APIs) and even Cisco IM&P APIs like Presence Web Services and EPASSoap.

And Zeep is a favorite way to implement these SOAP-based scripts and programs in Python.

The trouble is that SoapUI uses XML and Zeep expects JSON.

 

CHALLENGE:

Write a Python/Zeep script that allows you to copy and paste the XML from a working SOAP request in SoapUI into your Python code and automatically convert it into JSON that Zeep uses.  Here's the sample getPhone XML for the challenge:

 

 

 

 

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/12.5">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:getPhone>
         <name>INSERT PHONE NAME HERE</name>
         <returnedTags>
            <name></name>
            <description></description>
            <lines>
               <line>
                  <index>1</index>
                  <dirn>
                     <pattern></pattern>
                  </dirn>
                  <callInfoDisplay>
                     <callerName></callerName>
                  </callInfoDisplay>
                  <associatedEndusers>
                     <enduser>
                        <userId></userId>
                     </enduser>
                  </associatedEndusers>
               </line>
               <line>
                  <index>2</index>
                  <dirn>
                     <pattern></pattern>
                  </dirn>
                  <callInfoDisplay>
                     <callerName></callerName>
                  </callInfoDisplay>
                  <associatedEndusers>
                     <enduser>
                        <userId></userId>
                     </enduser>
                  </associatedEndusers>
               </line>
            </lines>
         </returnedTags>
      </ns:getPhone>
   </soapenv:Body>
</soapenv:Envelope>

 

 

 

 

 

 

RULES:

1. You must have at least two lines associated with the phone, which means you have to deal with duplicate tags in one request.

2. You must have at least two associated end users with one of the lines (there are at least 2 lines, but you can associate 2 or more users with as many of the lines as you want). 

3. You can implement it with a copy/paste into the code, or simply copy/paste it into a file and have your code read the file.

4. You can copy and paste everything between <ns:getPhone> and </ns:getPhone>, or copy and past the whole XML enchilada.  It's up to you.

5. Make sure your code displays the response from the SOAP request.

6. You can post just the code that performs the challenge, or an entire script with includes, etc.

 

Post (or attach a Python file to your post) your suggestions!  Anything, good or bad, will help the Community, so please chime in with your approaches! 

 

If someone posts something that is incorrect, overly complex, or too cryptic, please be considerate with your corrections or alternatives!  This is a TEAM sport!

 

1 Accepted Solution

Accepted Solutions

BjoernMartin
Spotlight
Spotlight

Hi!
Hope I followed all rule

I would be happy to receive feedback and suggestions for improvement.

 

Request
-------
Headers:
{'SOAPAction': '"CUCM:DB ver=12.5 getPhone"', 'Content-Type': 'text/xml; charset=utf-8'}

Body:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:getPhone xmlns:ns0="http://www.cisco.com/AXL/API/12.5">
      <name>SEP000000000000</name>
      <returnedTags>
        <name></name>
        <description></description>
        <lines>
          <line>
            <index>1</index>
            <dirn>
              <pattern></pattern>
            </dirn>
            <callInfoDisplay>
              <callerName></callerName>
            </callInfoDisplay>
            <associatedEndusers>
              <enduser>
                <userId></userId>
              </enduser>
            </associatedEndusers>
          </line>
          <line>
            <index>2</index>
            <dirn>
              <pattern></pattern>
            </dirn>
            <callInfoDisplay>
              <callerName></callerName>
            </callInfoDisplay>
            <associatedEndusers>
              <enduser>
                <userId></userId>
              </enduser>
            </associatedEndusers>
          </line>
        </lines>
      </returnedTags>
    </ns0:getPhone>
  </soap-env:Body>
</soap-env:Envelope>


Response
-------
Headers:
{'Set-Cookie': 'JSESSIONIDSSO=D1933AF99256FFB98FD039567AEA2433; Path=/; Secure; HttpOnly, JSESSIONID=C8037704C289A43167CA3A32B153E910; Path=/axl; Secure; HttpOnly', 'X-Frame-Options': 'SAMEORIGIN', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'Content-Security-Policy': "default-src *; script-src * 'unsafe-inline' 'unsafe-eval';style-src * 'unsafe-inline'; img-src * data: 'unsafe-inline';", 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Content-Type': 'text/xml;charset=UTF-8', 'Content-Length': '1041', 'Date': 'Mon, 09 May 2022 12:44:17 GMT', 'Server': ''}

Body:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:getPhoneResponse xmlns:ns="http://www.cisco.com/AXL/API/12.5">
      <return>
        <phone ctiid="4531" uuid="{FE2C4C44-F3DE-E447-1AFF-4DFE9C9ACF17}">
          <name>SEP000000000000</name>
          <description>#FN##LN##ID#</description>
          <lines>
            <line uuid="{B8FED489-97C3-B9D1-2780-C671F77B7D16}">
              <index>1</index>
              <dirn uuid="{7DE28330-7816-46D4-6E94-88ACAAE04467}">
                <pattern>\+1000</pattern>
              </dirn>
              <callInfoDisplay>
                <callerName>false</callerName>
              </callInfoDisplay>
              <associatedEndusers>
                <enduser>
                  <userId>user1000</userId>
                </enduser>
              </associatedEndusers>
            </line>
            <line uuid="{7E07AFA2-5491-9A1E-109A-D222A2AB6A24}">
              <index>2</index>
              <dirn uuid="{7CB6E096-2C8A-86DF-35EA-05649BE473C6}">
                <pattern>\+1001</pattern>
              </dirn>
              <callInfoDisplay>
                <callerName>false</callerName>
              </callInfoDisplay>
              <associatedEndusers>
                <enduser>
                  <userId>user1001</userId>
                </enduser>
              </associatedEndusers>
            </line>
          </lines>
        </phone>
      </return>
    </ns:getPhoneResponse>
  </soapenv:Body>
</soapenv:Envelope>

View solution in original post

2 Replies 2

BjoernMartin
Spotlight
Spotlight

Hi!
Hope I followed all rule

I would be happy to receive feedback and suggestions for improvement.

 

Request
-------
Headers:
{'SOAPAction': '"CUCM:DB ver=12.5 getPhone"', 'Content-Type': 'text/xml; charset=utf-8'}

Body:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:getPhone xmlns:ns0="http://www.cisco.com/AXL/API/12.5">
      <name>SEP000000000000</name>
      <returnedTags>
        <name></name>
        <description></description>
        <lines>
          <line>
            <index>1</index>
            <dirn>
              <pattern></pattern>
            </dirn>
            <callInfoDisplay>
              <callerName></callerName>
            </callInfoDisplay>
            <associatedEndusers>
              <enduser>
                <userId></userId>
              </enduser>
            </associatedEndusers>
          </line>
          <line>
            <index>2</index>
            <dirn>
              <pattern></pattern>
            </dirn>
            <callInfoDisplay>
              <callerName></callerName>
            </callInfoDisplay>
            <associatedEndusers>
              <enduser>
                <userId></userId>
              </enduser>
            </associatedEndusers>
          </line>
        </lines>
      </returnedTags>
    </ns0:getPhone>
  </soap-env:Body>
</soap-env:Envelope>


Response
-------
Headers:
{'Set-Cookie': 'JSESSIONIDSSO=D1933AF99256FFB98FD039567AEA2433; Path=/; Secure; HttpOnly, JSESSIONID=C8037704C289A43167CA3A32B153E910; Path=/axl; Secure; HttpOnly', 'X-Frame-Options': 'SAMEORIGIN', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'Content-Security-Policy': "default-src *; script-src * 'unsafe-inline' 'unsafe-eval';style-src * 'unsafe-inline'; img-src * data: 'unsafe-inline';", 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Content-Type': 'text/xml;charset=UTF-8', 'Content-Length': '1041', 'Date': 'Mon, 09 May 2022 12:44:17 GMT', 'Server': ''}

Body:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:getPhoneResponse xmlns:ns="http://www.cisco.com/AXL/API/12.5">
      <return>
        <phone ctiid="4531" uuid="{FE2C4C44-F3DE-E447-1AFF-4DFE9C9ACF17}">
          <name>SEP000000000000</name>
          <description>#FN##LN##ID#</description>
          <lines>
            <line uuid="{B8FED489-97C3-B9D1-2780-C671F77B7D16}">
              <index>1</index>
              <dirn uuid="{7DE28330-7816-46D4-6E94-88ACAAE04467}">
                <pattern>\+1000</pattern>
              </dirn>
              <callInfoDisplay>
                <callerName>false</callerName>
              </callInfoDisplay>
              <associatedEndusers>
                <enduser>
                  <userId>user1000</userId>
                </enduser>
              </associatedEndusers>
            </line>
            <line uuid="{7E07AFA2-5491-9A1E-109A-D222A2AB6A24}">
              <index>2</index>
              <dirn uuid="{7CB6E096-2C8A-86DF-35EA-05649BE473C6}">
                <pattern>\+1001</pattern>
              </dirn>
              <callInfoDisplay>
                <callerName>false</callerName>
              </callInfoDisplay>
              <associatedEndusers>
                <enduser>
                  <userId>user1001</userId>
                </enduser>
              </associatedEndusers>
            </line>
          </lines>
        </phone>
      </return>
    </ns:getPhoneResponse>
  </soapenv:Body>
</soapenv:Envelope>

Excellent!!  Elegance and simplicity! 

 

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: