Reputation: 55
I'm trying to fetch employee information from Workday using python using the Get_Workers method. However, it results in a failure. Is there any example available showing how to use it? The basic intention is to obtain the Employee's Location information.
Upvotes: 1
Views: 2895
Reputation: 156
Yes! Here is an example that shows how to use the suds module which is based on this gist of which I am not affiliated with.
This should provide a base that you can use to access whatever you need from Get_Workers
import secrets
import sys
from suds import client
from suds.wsse import Security, UsernameToken
from suds.sax.text import Raw
from suds.sudsobject import asdict
from suds import WebFault
wsdl_url = 'https://wd2-impl-services1.workday.com/ccx/service/yourTenantHere/Human_Resources/v32.0?wsdl'
Employee_ID = '139420'
client = client.Client(wsdl_url)
security = Security()
token = UsernameToken(secrets.username, secrets.password)
security.tokens.append(token)
client.set_options(wsse=security)
xmlstring = '''
<ns0:Worker_Reference>
<ns0:ID ns0:type="Employee_ID">{id}</ns0:ID>
</ns0:Worker_Reference>
'''.format(id=Employee_ID)
xml = Raw(xmlstring)
try:
result = client.service.Get_Workers(xml)
except WebFault as e:
# Employee ID probably doesn't exist.
print(e)
sys.exit()
def recursive_asdict(d):
"""Convert Suds object into serializable format."""
out = {}
for k, v in asdict(d).items():
if hasattr(v, '__keylist__'):
out[k] = recursive_asdict(v)
elif isinstance(v, list):
out[k] = []
for item in v:
if hasattr(item, '__keylist__'):
out[k].append(recursive_asdict(item))
else:
out[k].append(item)
else:
out[k] = v
return out
worker_dict = recursive_asdict(result)
worker = worker_dict['Response_Data']['Worker'][0]['Worker_Data']
lname = worker['Personal_Data']['Name_Data']['Legal_Name_Data']['Name_Detail_Data']['Last_Name']
print(lname)
Upvotes: 1