Back

Step by Step Guide to Building a Recruitee API Integration in PHP

Aug 17, 20245 minute read

Introduction

Hey there, fellow developer! Ready to supercharge your recruitment process? Let's dive into building a Recruitee API integration in PHP. This guide will walk you through the essentials, helping you leverage Recruitee's powerful features in your own applications. Buckle up!

Prerequisites

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

  • A PHP environment (7.4+ recommended)
  • Recruitee API credentials (you can snag these from your Recruitee account)
  • Composer installed (we'll use it to manage dependencies)

Setting up the project

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

mkdir recruitee-integration cd recruitee-integration composer init composer require guzzlehttp/guzzle

Authentication

Recruitee uses API tokens for authentication. Here's how to use it:

$apiToken = 'your_api_token_here'; $client = new GuzzleHttp\Client([ 'base_uri' => 'https://api.recruitee.com/c/your_company_id/', 'headers' => [ 'Authorization' => 'Bearer ' . $apiToken, 'Content-Type' => 'application/json' ] ]);

Making API requests

Now, let's make some requests! Here's a quick example for each type:

// GET request $response = $client->get('candidates'); // POST request $response = $client->post('candidates', [ 'json' => ['name' => 'John Doe', 'email' => '[email protected]'] ]); // PUT request $response = $client->put('candidates/123', [ 'json' => ['name' => 'John Updated Doe'] ]); // DELETE request $response = $client->delete('candidates/123');

Handling responses

Parsing responses is a breeze:

$data = json_decode($response->getBody(), true); if ($response->getStatusCode() !== 200) { throw new Exception('API request failed: ' . $data['error']); }

Implementing key features

Let's implement some core features:

// Fetch candidates $candidates = $client->get('candidates')->getBody(); // Create a job offer $newJob = $client->post('offers', [ 'json' => ['title' => 'Senior PHP Developer', 'description' => 'Join our awesome team!'] ]); // Update application status $client->patch('applications/456', [ 'json' => ['status' => 'hired'] ]); // Retrieve reports $reports = $client->get('reports')->getBody();

Best practices

Remember to:

  • Respect rate limits (Recruitee allows 180 requests per minute)
  • Implement caching where possible
  • Store your API token securely (use environment variables!)

Testing the integration

Don't forget to test! Here's a simple PHPUnit test to get you started:

public function testFetchCandidates() { $response = $this->client->get('candidates'); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getBody(), true); $this->assertArrayHasKey('candidates', $data); }

Conclusion

And there you have it! You're now equipped to build a robust Recruitee API integration. Remember, this is just the tip of the iceberg - Recruitee's API has tons more to offer. Happy coding, and may your applicant tracking be ever smooth!

For more details, check out the official Recruitee API documentation.