Official PHP client for the Mployr API
# Using Composer
composer require mployr/api-clientInitialize the client and make your first API call:
Configure the client in Laravel's service container.
// config/services.php
'Mployr' => [
'base_url' => env('MPLOYR_API_URL', 'https://api.mployr.com.au/v1'),
'email' => env('MPLOYR_API_EMAIL'),
'password' => env('MPLOYR_API_PASSWORD'),
],
// app/Providers/AppServiceProvider.php
use Mployr\ApiClient\MployrClient;
public function register(): void
{
$this->app->singleton(MployrClient::class, function ($app) {
$client = new MployrClient([
'base_url' => config('services.mployr.base_url'),
]);
$client->auth()->login([
'email' => config('services.mployr.email'),
'password' => config('services.mployr.password'),
]);
return $client;
});
}Create a new employee record.
<?php
$newPerson = $client->people()->create([
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john.doe@example.com',
'phone' => '+61 400 123 456',
'date_of_birth' => '1990-05-15',
]);
echo "Created person: " . $newPerson['data']['id'];Handle API errors gracefully.
<?php
use Mployr\ApiClient\Exceptions\ApiException;
use Mployr\ApiClient\Exceptions\ValidationException;
try {
$person = $client->people()->get(999);
} catch (ValidationException $e) {
// Handle validation errors
foreach ($e->getErrors() as $field => $messages) {
echo "$field: " . implode(', ', $messages) . "\n";
}
} catch (ApiException $e) {
echo "API Error: " . $e->getMessage() . "\n";
echo "Status: " . $e->getStatusCode() . "\n";
}See all available methods and endpoints in the interactive API reference.