How to fetch employees from Paylocity using Python
Editor's note: this article is part of a series on building third-party API integrations. Explore Merge if you’re looking to add 180+ integrations across HR and payroll, ATS, CRM, accounting, ticketing, marketing automation, and file storage with one unified API.
Paylocity is an all-inclusive Human Resources Information System (HRIS) that consolidates payroll, benefits, talent management, and other HR-related tasks into a single platform. Utilizing cloud technology, it provides instantaneous data and potent tools for businesses of varying sizes, augmenting efficiency and informed decision-making. Additionally, Paylocity boasts a potent API, enabling developers to weave its features into bespoke applications, allowing for automated extraction of employee information and other HR-centric data.
For a developer, extracting Employee data from a client's Paylocity system can automate HR procedures, curtail manual data input, and maintain data uniformity across several systems. This integration point empowers the developer to obtain real-time, precise employee data, which can subsequently be used to create robust applications, dashboards, or analytics tools that improve decision-making and workflow within the company.
Merge is a Unified API that facilitates developers in adding several integrations, Paylocity included, with a singular API. This article guides you on how to connect to the Paylocity API to acquire a list of Employees using both the Paylocity API and the Merge HRIS Unified API.
Setting Up Authentication for Paylocity API
When integrating with Paylocity API, one of the first steps you must undertake is configuring your authentication. Paylocity API uses OAuth 2.0 for authentication, specifically the Client Credentials grant type.
To authenticate, you will need to make a request to the token URL, which is <code class="blog_inline-code">https://api.paylocity.com/IdentityServer/connect/token</code>. This request should include your <code class="blog_inline-code">client_id</code>, <code class="blog_inline-code">client_secret</code>, and any other parameters that are required as body parameters.
The header of your request should be formatted in the following way:
After successfully exchanging tokens, you can find the <code class="blog_inline-code">access_token</code> by following the keys in the response. This token is crucial as it is used to authorize all your subsequent requests to the Paylocity API.
The token's lifespan, or how long it is valid, can be found in the <code class="blog_inline-code">expires_in</code> value in the response body. Once your token expires, you can use the <code class="blog_inline-code">refresh_token</code> key in the response to get a new one.
Remember, all requests to the Paylocity API must also include the header field <code class="blog_inline-code">Content-Type: application/x-www-form-urlencoded</code>. This ensures that the server interprets your request correctly.
In the above code, replace <code class='blog_inline-code'>YOUR_CLIENT_ID</code>, <code class='blog_inline-code'>YOUR_CLIENT_SECRET</code>, and <code class='blog_inline-code'>YOUR_DOMAIN</code> with your actual client ID, client secret, and domain.
This code first retrieves an access token using your client credentials. It then uses this token to authenticate the API requests. The employees are fetched page by page, and for each employee, additional details are fetched using their employee ID. The loop continues until there are no more employees to fetch (i.e., the response is empty).
An example of an individual item returned by this API Endpoint is:
FETCH Employees with Merge HRIS Unified API
The Merge API is a great way to pull normalized HRIS data from a variety of HRIS tools, including Paylocity.
When making requests to the Merge API, you will need to pass proper authentication parameters so that you can identify yourself as an authorized user. You'll need to include a Merge API Key (YOUR_API_KEY) and a Linked Account Token (END_USER_ACCOUNT_TOKEN) for every request you send to the Merge API.
Once you've authenticated to Merge, you'll next use the API client to make a GET request using the Linked Account Token of the customer whose data you're accessing.
The response you get back from the Merge API will include normalized data for any HRIS integration, including Paylocity. To explore the standard response format, check out the API reference at https://prod.cdn.paylocity.com/developer/index.html#tag/Company-Codes.
Now that you've accessed data via the Merge HRIS Unified API, you can easily add other integrations on behalf of any of your customers. Check out Merge Link to see how to automate your customers authorizing connections on your behalf and generating Linked Account Tokens.
Leveraging a Unified HRIS API for Efficient Integrations
Suppose you're not well-versed in programming languages such as Python, or perhaps Paylocity is merely one among multiple integrations that you and your team are tasked with developing and managing. This is where a Unified API like Merge steps in.
Merge proposes a solution for HRIS integrations by introducing a single API endpoint that connects to various platforms and services, Paylocity included. This API endpoint serves as a conduit between different platforms, enabling users to communicate with all of them via a single API endpoint.
Merge accomplishes this by utilizing a plugin system that enables it to establish connections to diverse platforms and services. These plugins form a bridge between Merge's API endpoint and the data housed in different HRIS applications. Each plugin is entrusted with managing the distinct communication protocols, APIs, and data structures of the system to which it connects.
When a user sends an API call to Merge, the call is directed to the suitable plugin based on the information given within the call. The plugin then processes the call and delivers the relevant response. This process facilitates users to engage with various systems via a single, Unified API endpoint.
Merge manages these integrations, streamlining authentication with a click-through UI component, and promptly identifying permissioning errors instigated by your customers (such as an incorrect API key). This substantially diminishes the long-term engineering effort associated with an integration product.In this guide, we demonstrated the process of using Python to communicate with the Paylocity API in order to retrieve Employee data.
For those seeking to connect with more than just a single HRIS application, Merge's unified API offers a robust solution. This single API allows you to tap into a multitude of HRIS platforms, Paylocity included, with just one call, thus removing the necessity for multiple separate integrations. This streamlines your integration ecosystem construction process, enabling you to concentrate on enhancing your primary product while simultaneously broadening your potential market.