0

Am interacting with a SOAP service through Zeep and so far it's been going fine, except I hit a snag with regards to dealing with passing values in anything related to an XSD extension.

I've tried multiple ways and am at my wits end.

campaignClient = Client("https://platform.mediamind.com/Eyeblaster.MediaMind.API/V2/CampaignService.svc?wsdl")
listPaging = {"PageIndex":0,"PageSize":5}
fact=campaignClient.type_factory("ns1")
parentType = fact.CampaignIDFilter
subtype=dict(parentType.elements)["CampaignID"] = (123456,)
combined= parentType(CampaignID=subtype)

rawData  = campaignClient.service.GetCampaigns(Paging=listPaging,CampaignsFilter=combined,  ShowCampaignExtendedInfo=False,_soapheaders=token)
print(rawData)

The context is the following : this service is to get a list of items and it's possible to apply a filter to it, which is a generic type. You can then implement any type of filter matching that type, here a CampaignIDFilter. My other attempts failed and the service used to pinpoint incorrect type or such but this way - which I think is on paper sound, gets me a 'something went wrong'.

I'm literraly implementing the solution found here : Creating XML sequences with zeep / python

Here's the service Doc http://platform.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3

Cheers

1 Answers1

0

Turns out the right way to get there was to hack around a bit to get the right structure and use of types. The code itself :

objectType = campaignClient.get_type('ns1:CampaignIDFilter')
objectWrap = xsd.Element('CampaignServiceFilter',objectType)
objectValue = objectWrap(CampaignID=123456)

wrapperT = campaignClient.get_type('ns1:ArrayOfCampaignServiceFilter')
wrapper = xsd.Element("CampaignsFilter",wrapperT)
outercontent = wrapper(objectValue)

This ends up generating the following XML :

<soap-env:Body>
   <ns0:GetCampaignsRequest xmlns:ns0="http://api.eyeblaster.com/message">
     <ns0:CampaignsFilter>
       <ns1:CampaignServiceFilter xmlns:ns1="http://api.eyeblaster.com/V1/DataContracts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:type="ns1:CampaignIDFilter">
         <ns1:CampaignID>123456</ns1:CampaignID>
       </ns1:CampaignServiceFilter>
     </ns0:CampaignsFilter>
     <ns0:Paging>
       <ns0:PageIndex>0</ns0:PageIndex>
       <ns0:PageSize>5</ns0:PageSize>
     </ns0:Paging>
     <ns0:ShowCampaignExtendedInfo>false</ns0:ShowCampaignExtendedInfo>
   </ns0:GetCampaignsRequest>
</soap-env:Body>

Much credit to the user here which gave me the boiler plate needed to get this lovecraftian horror to work how to specify xsi:type zeep python

  • https://python-zeep.readthedocs.io/en/master/datastructures.html says that you should be able to just do `objectType(CampaignID=123456)` and don't have to create an objectWrap. – paulie4 Apr 10 '20 at 22:58