0

I am attempting to call a Workday SOAP service using Zeep.

I am able to successfully call the service, add elements to filter the request, and get a response, but I need to specify a version attribute in the request element, and I cannot figure out how to add it:

service = client.create_service(
        '{urn:com.workday/bsvc/'+Human_Resources+'}'+Human_Resources+'Binding',
        'http://my-endpoint.com')

service_operation = 'Get_Job_Profiles'

request_filter = {'Response_Filter' : {
          'Page': 1,
          'Count' : 100, }}
#other things are added to the request_filter dict as well

response = getattr(service,service_operation)(**request_filter)

And this works fine. Zeep produces:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header>
        <ns0:Workday_Common_Header xmlns:ns0="urn:com.workday/bsvc">
            <ns0:Include_Reference_Descriptors_In_Response>true</ns0:Include_Reference_Descriptors_In_Response>
        </ns0:Workday_Common_Header>
# some other security related headers here #
    </soap-env:Header>
    <soap-env:Body xmlns:ns0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ns0:Id="id-3b0aa2ca-dc0f-417c-9168-498275645b16">
        <ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc">
            <ns0:Request_Criteria>
                <ns0:Transaction_Log_Criteria_Data>
                    <ns0:Transaction_Date_Range_Data>
                        <ns0:Updated_From>2000-01-01T00:00:00</ns0:Updated_From>
                        <ns0:Updated_Through>2018-05-09T00:00:00</ns0:Updated_Through>
                    </ns0:Transaction_Date_Range_Data>
                </ns0:Transaction_Log_Criteria_Data>
            </ns0:Request_Criteria>
            <ns0:Response_Filter>
                <ns0:As_Of_Entry_DateTime>2018-05-09T00:00:00</ns0:As_Of_Entry_DateTime>
                <ns0:Page>2</ns0:Page>
                <ns0:Count>100</ns0:Count>
            </ns0:Response_Filter>
            <ns0:Response_Group>
                <ns0:Include_Reference>true</ns0:Include_Reference>
                <ns0:Include_Job_Profile_Basic_Data>true</ns0:Include_Job_Profile_Basic_Data>
                <ns0:Include_Job_Classification_Data>true</ns0:Include_Job_Classification_Data>
                <ns0:Include_Workers_Compensation_Data>true</ns0:Include_Workers_Compensation_Data>
                <ns0:Include_Job_Profile_Compensation_Data>true</ns0:Include_Job_Profile_Compensation_Data>
            </ns0:Response_Group>
        </ns0:Get_Job_Profiles_Request>
    </soap-env:Body>
</soap-env:Envelope>

But now I need to add an attribute to:

<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc">

It needs to look like something like this:

<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc" ns0:version="v29">

Here is the definition from the xsd:

<xsd:complexType name="Get_Job_Profiles_RequestType">
<xsd:annotation>
    <xsd:documentation>Request element used to find and get Job Profiles and their associated data.</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
    <xsd:element name="Request_References" type="wd:Job_Profile_Request_ReferencesType" minOccurs="0"/>
    <xsd:element name="Request_Criteria" type="wd:Job_Profile_Request_CriteriaType" minOccurs="0"/>
    <xsd:element name="Response_Filter" type="wd:Response_FilterType" minOccurs="0"/>
    <xsd:element name="Response_Group" type="wd:Job_Profile_Response_GroupType" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute ref="wd:version"/></xsd:complexType>

It's easy enough to add an element and a value, but I am stumped on how to add an attribute to an element.

1 Answers1

0

Zeep is smart, all I needed to do was add it as a kwarg:

Before:

response = getattr(service,service_operation)(**request_filter)

After:

response = getattr(service,service_operation)(**request_filter, version='v29.1')

Thus producing:

<ns0:Get_Job_Profiles_Request xmlns:ns0="urn:com.workday/bsvc" ns0:version="v29.1">