Back

Step by Step Guide to Building a UKG Ready API Integration in Ruby

Aug 11, 20246 minute read

Introduction

Hey there, fellow developer! Ready to dive into the world of UKG Ready API integration? You're in for a treat. We'll be building a slick Ruby integration that'll have you pulling employee data, managing time and attendance, and accessing payroll info like a pro. Let's get cracking!

Prerequisites

Before we jump in, make sure you've got:

  • Ruby 2.7+ installed
  • The httparty and dotenv gems
  • Your UKG Ready API credentials (if you don't have these, go bug your admin!)

Setting up the project

First things first, let's get our project set up:

mkdir ukg_ready_integration cd ukg_ready_integration bundle init

Now, add these gems to your Gemfile:

gem 'httparty' gem 'dotenv'

Run bundle install, and you're good to go!

Authentication

Alright, let's tackle authentication. UKG Ready uses OAuth 2.0, so we'll need to get an access token:

require 'httparty' require 'dotenv/load' class UKGReadyClient include HTTParty base_uri 'https://api.ultipro.com' def initialize @token = get_token end private def get_token response = self.class.post('/auth/token', body: { grant_type: 'client_credentials', client_id: ENV['UKG_CLIENT_ID'], client_secret: ENV['UKG_CLIENT_SECRET'] } ) response.parsed_response['access_token'] end end

Pro tip: Use environment variables for your credentials. Never hardcode them!

Making API requests

Now that we're authenticated, let's make some requests:

def get_employees self.class.get('/personnel/v1/employees', headers: { 'Authorization' => "Bearer #{@token}" } ) end

Easy peasy, right? Just remember to include that token in your headers.

Working with UKG Ready endpoints

UKG Ready has a ton of endpoints. Here's a quick example for time and attendance:

def get_timecards(start_date, end_date) self.class.get("/timemanagement/v1/timecards?startDate=#{start_date}&endDate=#{end_date}", headers: { 'Authorization' => "Bearer #{@token}" } ) end

Error handling and logging

Don't forget to handle those pesky errors:

def api_request response = yield if response.success? response else logger.error "API error: #{response.code} - #{response.body}" raise "API request failed" end end

Data parsing and manipulation

JSON is your friend here. Parse those responses and transform the data as needed:

def get_employee_names response = api_request { get_employees } response.parsed_response['data'].map { |employee| employee['name'] } end

Building reusable components

As your integration grows, you'll want to break things out into modules:

module UKGReady module Employees def get_employees # ... end end module TimeManagement def get_timecards # ... end end end class UKGReadyClient include UKGReady::Employees include UKGReady::TimeManagement # ... end

Testing the integration

Don't skimp on testing! Here's a quick example using RSpec:

RSpec.describe UKGReadyClient do let(:client) { UKGReadyClient.new } describe '#get_employees' do it 'returns a list of employees' do VCR.use_cassette('employees') do response = client.get_employees expect(response).to be_success expect(response.parsed_response['data']).to be_an(Array) end end end end

Best practices and optimization

Remember to respect rate limits and implement caching where it makes sense. Your future self will thank you!

Conclusion

And there you have it! You've just built a solid foundation for your UKG Ready API integration. From here, you can expand on this base, add more endpoints, and really make it sing.

Remember, the key to a great integration is clean, modular code and robust error handling. Now go forth and integrate with confidence!

Happy coding!