getsno/relesys-users
Laravel 10 / PHP 8.1 client for the Relesys User Management API. Authenticate via client ID/secret and access endpoints for users, departments, user groups, custom fields, and communication, with support for filtering, sorting, and pagination.
composer require getsno/relesys-users
.env:
RELESYS_CLIENT_ID=your_client_id
RELESYS_CLIENT_SECRET=your_client_secret
use Getsno\Relesys\Facades\Relesys;
// Fetch a single user
$user = Relesys::users()->getUser('user-uuid-here');
use Getsno\Relesys\Facades\Relesys;
use Getsno\Relesys\Api\UserManagement\Entities\User;
$user = User::fromArray([
'name' => 'John Doe',
'email' => 'john@example.com',
'primaryDepartmentId' => 'dept-uuid-here',
]);
$createdUser = Relesys::users()->createUser($user);
Getsno\Relesys\Facades\Relesys (primary entry point)Getsno\Relesys\Api\UserManagement\Entities (e.g., User, UserPatch)Getsno\Relesys\Api\UserManagement\Enums (e.g., UserStatus)/tests directory for real-world usage patterns// Create
$user = Relesys::users()->createUser($userData);
// Read (single)
$user = Relesys::users()->getUser('user-uuid');
// Read (batch with pagination)
$users = Relesys::users()->getUsers(
queryParams: (new ApiQueryParams)->limit(10)->page(1),
include: ['customFields']
);
// Update (partial)
$userPatch = (new UserPatch())
->title('Updated Title')
->status(UserStatus::Disabled);
Relesys::users()->updateUser('user-uuid', $userPatch);
// Delete
Relesys::users()->deleteUser('user-uuid');
Query Parameters:
$query = (new ApiQueryParams)
->addFilter('status', UserStatus::Activated->value)
->sortBy('name', 'asc')
->limit(50);
Nested Relationships:
// Fetch user with departments and groups
$user = Relesys::users()->getUser('user-uuid', include: ['departments', 'userGroups']);
Bulk Operations:
// Update multiple users (via API's bulk endpoint)
$users = Relesys::users()->updateUsers($userPatches);
Communication Endpoints:
// Send message template
$message = Relesys::communication()->sendMessageTemplate(
'template-uuid',
['user-uuid-1', 'user-uuid-2']
);
Relesys::users()->updateUser($userId, $patch)
->then(fn() => event(new UserUpdated($userId)));
class UserService {
public function createUserInDepartment(array $data, string $departmentId) {
$user = User::fromArray($data + ['primaryDepartmentId' => $departmentId]);
return Relesys::users()->createUser($user);
}
}
$groups = cache()->remember("relesys:user-groups", now()->addHours(1), fn() =>
Relesys::userGroups()->getUserGroups()
);
Empty Arrays in Custom Fields:
customFields. Use null instead.$user = User::fromArray([
'customFields' => null, // Instead of []
]);
Phone Number Format:
countryCode and number as separate fields.$phone = [
'countryCode' => 44, // UK
'number' => '7123456789',
];
Pagination Handling:
hasMore in batch responses for incomplete results.$users = Relesys::users()->getUsers($queryParams);
while ($users->hasMore) {
$users = Relesys::users()->getUsers($queryParams->page($users->page + 1));
}
UUID Validation:
123e4567-e89b-12d3-a456-426614174000).Illuminate\Support\Str::isUuid($id).Rate Limiting:
use Illuminate\Support\Facades\Http;
Http::withOptions(['timeout' => 30])->retry(3, 100);
Relesys::setDebug(true); // Logs all API requests/responses
Http::fake([
'api.relesysapp.net/*' => Http::response([], 200),
]);
RelesysHttpClientException for non-2xx responses. Catch and inspect:
try {
Relesys::users()->getUser('invalid-uuid');
} catch (RelesysHttpClientException $e) {
logger()->error('Relesys API Error:', [
'status' => $e->getStatusCode(),
'response' => $e->failedRequest->body(),
]);
}
Environment Variables:
RELESYS_CLIENT_ID and RELESYS_CLIENT_SECRET are set in .env..env.local to avoid committing secrets.API Scope Requirement:
relesys.api.users scope is mandatory for user management. Verify with Relesys support if you encounter 403 errors.Timezone Handling:
$user->birthDate->setTimezone('Europe/Oslo');
Custom Entities:
User) to add application-specific fields:
class AppUser extends User {
public function getFullName(): string {
return "{$this->title} {$this->name}";
}
}
Middleware:
Relesys::getHttpClient()->middleware(function ($request) {
$request->header('X-Custom-Header', 'value');
});
Event Dispatching:
Relesys::users()->getUser($id)->then(fn() => event(new UserFetched($id)));
Testing:
// In tests/Feature/UserManagementTest.php
public function test_user_creation() {
Http::fake([
'api.relesysapp.net/users' => Http::response(['id' => 'test-uuid'], 201),
]);
// Test logic...
}
How can I help you explore Laravel packages today?