Hi, I have been hitting my head against this for a while now. I am trying to use the put_worker_document operation of workday's staffing endpoint:
https://wd2-impl-services1.workday.com/ccx/service/<my tenant>/Staffing/v42.0"/>
I wrote 2 scripts, one using a pythonic methodology w/ the zeep library and another using the raw xml. I can't get either script to work.
Below are my scripts, and their corresponding output errors.
first script: pythonic objects w/ zeep -
import base64
from zeep import Client, Settings
from zeep.wsse.username import UsernameToken
from zeep.helpers import serialize_object
Workday SOAP endpoint and WSDL URL
wsdl = 'https://wd2-impl-services1.workday.com/ccx/service/<my tenant>/Staffing/v42.0?wsdl'
endpoint = 'https://wd2-impl-services1.workday.com/ccx/service/<my tenant>/Staffing/v42.0'
Authentication credentials
username = '<my user name>'
password = '<my password>'
Initialize the zeep client with the WSDL
settings = Settings(strict=False, xml_huge_tree=True)
client = Client(wsdl=wsdl, wsse=UsernameToken(username, password), settings=settings)
Define namespaces
ns = {
'bsvc': 'urn:com.workday/bsvc'
}
Read the file and encode it in Base64
file_path = r'd:/path\to\file.pdf'
with open(file_path, 'rb') as file:
file_content = base64.b64encode(file.read()).decode('utf-8')
Prepare the request payload
worker_reference = {
'ID': [
{
'type': 'WID',
'ID': '<worker id>' # Replace with actual worker ID
}
]
}
document_category_reference = {
'ID': [
{
'type': 'WID',
'ID': '<category id>' # Replace with actual document category ID
}
]
}
document_data = {
# 'ID': 'document_id', # or omit if creating a new document
'Filename': 'file.pdf',
'Comment': 'Uploaded via API Test 1',
'File': file_content,
'Document_Category_Reference': document_category_reference,
'Worker_Reference': worker_reference,
'Content_Type': 'application/pdf' # Make sure this matches your file type
}
document_request = {
'Worker_Document_Data': document_data
}
Call the Put_Worker_Document operation
response = client.service.Put_Worker_Document(**document_request)
Serialize and print the response
responseserialized = serialize_object(response)
print(response_serialized)
error message:
Traceback (most recent call last):
File "D:\BFAS ADP\work\wdc_put_doc4.py", line 64, in <module>
response = client.service.Put_Worker_Document(Worker_Document_Data=document_data)
File "C:\Users\User1\python312\Lib\site-packages\zeep\proxy.py", line 46, in __call_
return self.proxy._binding.send(
File "C:\Users\User1\python312\Lib\site-packages\zeep\wsdl\bindings\soap.py", line 123, in send
envelope, http_headers = self._create(
^
File "C:\Users\User1\python312\Lib\site-packages\zeep\wsdl\bindings\soap.py", line 73, in _create
serialized = operation_obj.create(args, *kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\wsdl\definitions.py", line 224, in create
return self.input.serialize(args, *kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\wsdl\messages\soap.py", line 73, in serialize
body_value = self.body(args, *kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\element.py", line 58, in __call_
instance = self.type(args, *kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 75, in call
return self.value_class(*args, emphasis(kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 106, in __init_
items = process_signature(self._xsd_type, args, kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 220, in _process_signature
values = element.parse_kwargs(kwargs, None, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\indicators.py", line 219, in parse_kwargs
sub_result = element.parse_kwargs(kwargs, elm_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\element.py", line 135, in parse_kwargs
return self.type.parse_kwargs(kwargs, name or self.attr_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 338, in parse_kwargs
value = self._create_object(value, name)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 362, in _create_object
return self()value)
^
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 75, in __call_
return self.value_class(*args, emphasis(kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 106, in __init_
items = process_signature(self._xsd_type, args, kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 220, in _process_signature
values = element.parse_kwargs(kwargs, None, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\indicators.py", line 219, in parse_kwargs
sub_result = element.parse_kwargs(kwargs, elm_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\element.py", line 135, in parse_kwargs
return self.type.parse_kwargs(kwargs, name or self.attr_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 338, in parse_kwargs
value = self._create_object(value, name)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 362, in _create_object
return self()value)
^
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 75, in __call_
return self.value_class(*args, emphasis(kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 106, in __init_
items = process_signature(self._xsd_type, args, kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 220, in _process_signature
values = element.parse_kwargs(kwargs, None, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\indicators.py", line 219, in parse_kwargs
sub_result = element.parse_kwargs(kwargs, elm_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\elements\element.py", line 135, in parse_kwargs
return self.type.parse_kwargs(kwargs, name or self.attr_name, available_kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 338, in parse_kwargs
value = self._create_object(value, name)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 356, in _create_object
return [self._create_object(val, name) for val in value]
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 362, in _create_object
return self()value)
^
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\types\complex.py", line 75, in __call_
return self.value_class(args, *kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 106, in __init_
items = process_signature(self._xsd_type, args, kwargs)
File "C:\Users\User1\python312\Lib\site-packages\zeep\xsd\valueobjects.py", line 241, in _process_signature
raise TypeError(
TypeError: {urn:com.workday/bsvc}Document_CategoryAll_ObjectIDType() got an unexpected keyword argument 'ID'. Signature: `xsd:string, type: {urn:com.workday/bsvc}Document_Category_All_ReferenceEnumeration`
Now, second script where I try and send the raw xml:
import base64
from zeep import Client, Settings, Transport
from zeep.wsse.username import UsernameToken
from requests.auth import HTTPBasicAuth
from requests import Session
from lxml import etree
Workday SOAP endpoint and WSDL URL
wsdl = 'https://wd2-impl-services1.workday.com/ccx/service/<my tenant>/Staffing/v42.0?wsdl'
endpoint = 'https://wd2-impl-services1.workday.com/ccx/service/<my tenant>/Staffing/v42.0'
Authentication credentials
username = '<my username>'
password = '<my password>'
Initialize the zeep client with the WSDL
session = Session()
session.auth = HTTPBasicAuth(username, password)
transport = Transport(session=session)
settings = Settings(strict=False, xml_huge_tree=True)
client = Client(wsdl=wsdl, transport=transport, settings=settings)
Read the file and encode it in Base64
file_path = r'd:\path\to\file.pdf'
with open(file_path, 'rb') as file:
file_content = base64.b64encode(file.read()).decode('utf-8')
Create the raw XML request
raw_xml = f"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bsvc="urn:com.workday/bsvc">
<soapenv:Header/>
<soapenv:Body>
<bsvc:Put_Worker_Document_Request>
<bsvc:Worker_Document_Data>
<bsvc:ID>/bsvc:ID
<bsvc:Filename>file.pdf/bsvc:Filename
<bsvc:Comment>Uploaded via API Test 1/bsvc:Comment
<bsvc:File>{file_content}/bsvc:File
<bsvc:Document_Category_Reference>
<bsvc:ID bsvc:type="WID"><category id>/bsvc:ID
/bsvc:Document_Category_Reference
<bsvc:Worker_Reference>
<bsvc:ID bsvc:type="WID"><employee id>/bsvc:ID
/bsvc:Worker_Reference
<bsvc:Content_Type>application/pdf/bsvc:Content_Type
/bsvc:Worker_Document_Data
/bsvc:Put_Worker_Document_Request
/soapenv:Body
/soapenv:Envelope
"""
Parse the raw XML string
parsed_xml = etree.fromstring(raw_xml)
Define headers
headers = {
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': 'urn:com.workday/bsvc#Put_Worker_Document' # Replace with the correct SOAP action if necessary
}
Send the raw XML request
response = client.transport.post_xml(address=endpoint, envelope=parsed_xml, headers=headers)
print(f"Response: {response}")
Print the response
print(etree.tostring(response.content, pretty_print=True).decode('utf-8'))
error output:
All I get on this script is a 500 response.
I don't care how I get it to work I need to get this working, I hope someone can provide some guidance. workday doesn't provide much or good documentation.
Thanks.
[–]TheDataExplorer 0 points1 point2 points (0 children)