无法使用Get_Workers()(python)从{{Workday}获取员工信息

时间:2019-04-26 07:08:52

标签: workday-api

我正在尝试使用Get_Workers方法使用python从Workday获取员工信息。但是,这会导致失败。是否有可用的示例说明如何使用它?基本目的是获取员工的位置信息。

1 个答案:

答案 0 :(得分:0)

是的!这是显示如何使用 suds 模块的示例 基于this gist of which I am not affiliated with

这应该提供一个基础,您可以使用它来访问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)