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!
Before we jump in, make sure you've got:
First things first, let's set up our project:
mkdir recruitee-integration cd recruitee-integration composer init composer require guzzlehttp/guzzle
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' ] ]);
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');
Parsing responses is a breeze:
$data = json_decode($response->getBody(), true); if ($response->getStatusCode() !== 200) { throw new Exception('API request failed: ' . $data['error']); }
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();
Remember to:
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); }
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.