How to GET employees from the Workday API with Python
Editor's note: This is a series on API-based integrations. Check out Merge if you're looking to add 40+ HRIS integrations with one HRIS API.
If you’re building a direct integration with Workday, one of the most basic things you’ll want to do is pull employees from the Workday API. The following article covers how you can start interacting with Workday’s SOAP API.
As a note from the authors (who’ve built an entire Workday integration), we truly believe the quickest way to get a Workday integration is via a unified API provider, such as Merge.
In this article, we'll cover how to understand Workday's SOAP API, how to set proper permissions in Workday, and how to write a GET request to Workday's SOAP API in Python.
Understanding Workday’s SOAP API
While most modern applications structure their APIs with a REST architecture, Workday employs an architecture known as SOAP. SOAP stands for Simple Object Access Protocol, and returns information with the following format:
Authentication and permissions with the Workday API
Getting permissions for Workday HRIS and ATS
In order to begin receiving SOAP responses from Workday, you need to create an Integrated System User (ISU) with the proper permissions. Workday configures their permissions on a field level, so you’ll need to grant yourself access to a number of fields to get things up and running.
Please note that the following steps will need to be accomplished by a Workday user with administrative access.
- Access the Create Integration System User task through Workday’s search bar and create a new user
- Add the new user to the list of System Users in order to guarantee the password you created does not expire
- Access the Create Security Group task and create a new User-Based Security Group
- Add the Integration System User you’ve created to the group and save your progress
After step four, you’ll need to follow different processes depending on which Workday API endpoints you wish to pull data from.
Accessing the Workday HRIS API
- Search Workday for Public Web Services
- Open the report
- Hover over Human Resources and click the three dots to access the menu
- Click Web Service, then View WSDL
- Navigate to the bottom of the WSDL page to find the hostname
- Look for the Username, Password, Tenant Name <code class="blog_inline-code">https://wd5-services1.workday.com/TENANT_NAME</code>, and Endpoint URL. Save these somewhere secure for later
Accessing the Workday ATS API
- Navigate to the Domain Security Policy tab under Web Service
- Search for Recruiting Web Services
- Add permissions to the User’s Security Group for the endpoints you’ll be accessing (for example Get_Applicants, Get_Job_Postings, etc.)
- Look for the Username, Password, Tenant Name <code class="blog_inline-code">https://wd5-services1.workday.com/TENANT_NAME</code>, and Endpoint URL under the User’s Security Group. Save these somewhere secure for later.
How to GET employees from the Workday API in Python
Set up your request file
Open up a new Python file, and call it workday_requester.py
Import <code class="blog_inline-code">json</code>, <code class="blog_inline-code">requests</code>, and <code class="blog_inline-code">xmltodict</code> from parse.
As we mentioned above, the Workday API returns responses in XML. You, like most developers, are probably used to a dictionary. <code class="blog_inline-code">xmltodict</code> lets us parse the response by returning an ordered dictionary that we can then turn into a dictionary.
Create and store the tenant_name, your username, password, and url from Step 4 as variables.
Construct your SOAP request body
Below is an example of the request body you would use to fetch employees using the Get Workers Endpoint. You’ll need to tweak this request body to fit the API endpoint you’d like to call.
Note that to deal with pagination, you need to set a page number for the request as well. Save this as a variable.
SOAP requests contain 2-4 blocks. You can think of a block as similar structure HTML, which requires both an opening and closing tag. The SOAP blocks are Envelope, Header, Body, and Fault. For a basic SOAP request, only the Envelope and Body are required.
To get employees, we’ll need to use the Envelope, Header, and Body blocks.
To help you think about the structure of SOAP, you can think of a SOAP Request as a "package," the Envelope is being the "packaging," the Header is the "Sent from Address," and the Body is the "letter/contents" of the package.
We’ll first create the Envelope with a namespace attribute <code class="blog_inline-code">xmlns:soapenv=”https://schemas.xmlsoap.org/soap/envelope/”</code>.
Our opening Envelope block will look something like this:
The other two blocks (the Header and Body) will be wrapped inside this Envelope.
The Header will contain our API access credentials and the security needed to access it. Alone, the header will look like this:
The bulk of our actual request will be in the Body. There, we will define the parameters and data we’d like to fetch.
For our example, we’re making a <code class="blog_inline-code">Get_Workers_Request</code>, and because we’re also using pagination we’ll want to pass page_number as a parameter.
To call a different endpoint, change the bsvc payload in the SOAP body to the endpoint of your choosing.
Note how we’re leaving out <code class="blog_inline-code">soapenv:Fault</code>, which would generally be used to catch error codes when your SOAP API call is incomplete.
Look at the example below to see how the Envelope, Header, and Body all fit together in a SOAP request.
Pull and format your Workday API employee request
We’ll then want to make the call by calling requests with the URL and request body. In a traditional REST API call we would use <code class="blog_inline-code">method=”GET”</code>, but with SOAP we’ll be calling <code class="blog_inline-code">POST</code> to the <code class="blog_inline-code">Get_Workers_Request</code> endpoint to access this data.
In order to make the resulting response more readable, we can use json.loads and the parse method to convert the response to a dictionary.
The resulting response will look similar to this:
We’ve shortened the response here, but the response will likely include fields like the employees contact information, hire date, weekly hours and more!
And that’s it! You’ve successfully pulled the employees object from the Workday API.
At Merge, we’ve built a Unified API that lets you easily pull from Workday using REST (no SOAP required). Our HRIS Unified API has also smoothed out pagination and authentication. We offer over 180+ integrations, including Workday, BambooHR, and UKG.
You can learn more about Merge by scheduling a demo with one of our integration experts.