laravel-rt-bestpratical maintained by samuel-olavo
Laravel RT (Best Practical) Integration
Laravel package to interact with Request Tracker (RT) through the REST2 API. Supports token, basic auth and client-certificate (mTLS) authentication. Compatible with Laravel 10 → 13 and PHP 8.2+.
API reference: https://docs.bestpractical.com/rt/6.0.2/RT/REST2.html
Installation
composer require samuel-olavo/laravel-rt-bestpratical
Publish the configuration (optional — a config merge is provided by default):
php artisan vendor:publish --provider="SamuelOlavo\LaravelRTBestpratical\RTServiceProvider" --tag=rt-config
Set in .env:
RT_BASE_URL="https://my.rt.server/REST/2.0"
RT_API_TOKEN="your-api-token"
For mTLS, set RT_CERTIFICATE=true and the certificate paths (see
.env.example).
Usage
Resolve the service from the container (singleton) or via the rt alias:
use SamuelOlavo\LaravelRTBestpratical\RTService;
$rt = app(RTService::class); // or app('rt')
Create a ticket
$ticket = $rt->createTicket([
'Queue' => 'helpdesk',
'Subject' => 'Resource request',
'Requestor' => $user->email, // the requestor is the authenticated user
'Content' => '<p>Details…</p>',
'ContentType' => 'text/html',
]);
// $ticket['id'] and $ticket['_url'] available
With attachments:
$rt->createTicketWithAttachments($data, [
['path' => storage_path('app/request.pdf'), 'name' => 'request.pdf', 'type' => 'application/pdf'],
]);
Reply and close (helpdesk flow)
// Reply to the requestor and mark as resolved
$rt->resolveTicket($ticketId, 'Your request has been approved and provisioned.');
// Reply only (without closing)
$rt->replyToTicket($ticketId, 'We are still working on this.');
// Internal comment (not visible to the requestor)
$rt->commentOnTicket($ticketId, 'Internal note for the team.');
// Reject with a reason
$rt->rejectTicket($ticketId, 'Request rejected. Reason: …');
Ticket management
$rt->getTicket($ticketId);
$rt->updateTicket($ticketId, ['Priority' => 20]);
$rt->assignTicket($ticketId, 'john');
$rt->setStatus($ticketId, 'open');
$rt->setCustomFields($ticketId, ['Area' => 'Network']);
$rt->addWatchers($ticketId, ['Cc' => ['boss@dei.uc.pt']]);
$rt->linkTicket($ticketId, ['Add' => ['RefersTo' => 'ticket/2']]);
$rt->getTicketHistory($ticketId);
$rt->deleteTicket($ticketId); // status -> deleted
Search
// Simple TicketSQL
$rt->searchTickets("Queue = 'helpdesk' AND Status = 'open'", [
'orderby' => 'Created', 'order' => 'DESC', 'per_page' => 20,
]);
// Shortcut by queue/status
$rt->ticketsByQueue('helpdesk', 'open');
Queues and users
$rt->listQueues();
$rt->getQueue('helpdesk');
$rt->listUsers(['query' => '...']);
$rt->getUser('john');
$rt->createUser(['Name' => 'john', 'EmailAddress' => 'john@dei.uc.pt']);
Health-check
$rt->version(); // GET /rt — confirms connection and version
Error handling
On an HTTP or transport error, a
SamuelOlavo\LaravelRTBestpratical\Exceptions\RTException is thrown, with
getStatusCode() and getResponseBody():
use SamuelOlavo\LaravelRTBestpratical\Exceptions\RTException;
try {
$rt->resolveTicket($ticketId, 'Resolved.');
} catch (RTException $e) {
report($e);
// $e->getStatusCode(); $e->getResponseBody();
}
Available methods
Tickets: createTicket, createTicketWithAttachments, getTicket,
updateTicket, deleteTicket, replyToTicket, replyToTicketWithAttachments,
commentOnTicket, setStatus, resolveTicket, openTicket, rejectTicket,
stallTicket, assignTicket, setPriority, setCustomFields, addWatchers,
linkTicket, getTicketHistory, searchTickets, ticketsByQueue.
Queues/users: listQueues, getQueue, listUsers, getUser, createUser.
Utilities: version.
Backward-compatible (deprecated): addResponseToTicket, addCommentToTicket,
listTickets, addCommentOrCorrespondence.
License
MIT.