Website • Documentation • Pricing
Treblle is an API intelligence platfom that helps developers, teams and organizations understand their APIs from a single integration point.
A Laravel SDK for Treblle Observability as a Service (OaaS). Easily retrieve and filter requests from APIs monitored by Treblle and expose that data to your end-customers.
- PHP 8.1 or higher
- Laravel 10.0 or higher
- Guzzle HTTP 7.0 or higher
Install the package via Composer:
composer require treblle/oaas-laravel
The package will automatically register its service provider. Publish the configuration file:
php artisan vendor:publish --tag=treblle-oaas-config
Add your Treblle OaaS API token to your .env
file:
TREBLLE_OAAS_API_TOKEN=your_api_token_here
You can obtain your API token from the Treblle Identity Dashboard under Developer Settings.
To use the SDK you will need to pass your Workspace ID (found in Workspace Settings on the Treblle Dashboard) and your API ID (found in API Settings on the Treblle Dashboard)
use Treblle\OaaS\Facades\TreblleOaaS;
// Get all requests for a customer
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->get();
foreach ($requests as $request) {
echo "Request: {$request->getMethod()} {$request->getPath()}" . PHP_EOL;
echo "Status: {$request->getHttpCode()}" . PHP_EOL;
echo "Load Time: {$request->getLoadTimeMs()}ms" . PHP_EOL;
}
The SDK provides a fluent API for filtering requests:
use Treblle\OaaS\Enums\HttpMethod;
use Treblle\OaaS\Enums\Device;
use Treblle\OaaS\Enums\TimePeriod;
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->whereMethod(HttpMethod::POST)
->whereDevice(Device::IOS)
->whereTimePeriod(TimePeriod::LAST_24_HOURS)
->whereSuccessful() // 2xx status codes
->withoutProblems()
->sortByLoadTimeSlowest()
->limit(10)
->get();
// Custom time range filtering (alternative to whereTimePeriod)
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->whereTimeRange('2025-09-01 00:00:00', '2025-09-30 23:59:59')
->get();
// Get all-time requests
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->allTime()
->get();
// Search checkout requests for specific payment methods
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->withParams('stripe') // Find requests with Stripe payment data
->whereMethod(HttpMethod::POST)
->get();
// Find user registration attempts with Gmail addresses
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->withParams('@gmail.com') // Partial match on email domains
->get();
// Get paginated results
$page1 = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->paginate(perPage: 20, page: 1);
echo "Total requests: {$page1->total()}" . PHP_EOL;
echo "Current page: {$page1->currentPage()} / {$page1->totalPages()}" . PHP_EOL;
// Check if there are more pages
if ($page1->hasNextPage()) {
$page2 = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->paginate(perPage: 20, page: 2);
}
Get detailed information about a specific request:
$requestDetails = TreblleOaaS::getRequest('workspace-id', 'api-id', 'request-id');
echo "Request URL: {$requestDetails->getRequestUrl()}" . PHP_EOL;
echo "Response Body: " . json_encode($requestDetails->getResponseBody()) . PHP_EOL;
echo "Server Info: " . json_encode($requestDetails->getServerInfo()) . PHP_EOL;
// Check compliance and security
if ($requestDetails->hasProblem()) {
echo "Request has problems: " . json_encode($requestDetails->getProblem()) . PHP_EOL;
}
$compliance = $requestDetails->getComplianceReport();
echo "Compliance Status: {$compliance['status']}" . PHP_EOL;
echo "Compliance Score: {$compliance['overall_percentage']}%" . PHP_EOL;
Filter Method | Description |
---|---|
whereCustomer(string $customerId) |
Filter by external user/customer ID |
whereLocation(string $location) |
Filter by geographic location |
withParams(string $params) |
Filter by request parameters |
whereMethod(HttpMethod $method) |
Filter by HTTP method |
whereDevice(Device $device) |
Filter by device type (iOS/Android/Desktop) |
whereHttpCode(int|string $code) |
Filter by HTTP status code |
whereSuccessful() |
Filter for 2xx responses |
whereClientError() |
Filter for 4xx responses |
whereServerError() |
Filter for 5xx responses |
whereTimePeriod(TimePeriod $period) |
Filter by time period |
whereTimeRange(string $start, string $end) |
Filter by custom date range (YYYY-MM-DD HH:MM:SS format) |
allTime() |
Get all requests regardless of time period |
withProblems() |
Only requests with problems |
withoutProblems() |
Only requests without problems |
Sort Method | Description |
---|---|
sortByCreatedAtDesc() |
Most recent first (default) |
sortByCreatedAtAsc() |
Oldest first |
sortByLoadTimeFastest() |
Fastest requests first |
sortByLoadTimeSlowest() |
Slowest requests first |
Request summary objects provide helpful methods:
foreach ($requests as $request) {
// Status checks
if ($request->isSuccessful()) {
echo "✅ Successful request" . PHP_EOL;
} elseif ($request->hasClientError()) {
echo "⚠️ Client error: {$request->getHttpCode()}" . PHP_EOL;
} elseif ($request->hasServerError()) {
echo "❌ Server error: {$request->getHttpCode()}" . PHP_EOL;
}
// Performance checks
if ($request->isLoadTimeFast()) {
echo "⚡ Fast response: {$request->getLoadTimeMs()}ms" . PHP_EOL;
} else {
echo "🐌 Slow response: {$request->getLoadTimeMs()}ms" . PHP_EOL;
}
// Customer info
if ($displayName = $request->getCustomerDisplayName()) {
echo "Customer: {$displayName}" . PHP_EOL;
}
// Security info
echo "Threat Level: {$request->getThreatLevel()}" . PHP_EOL;
echo "Has Auth: " . ($request->hasAuth() ? 'Yes' : 'No') . PHP_EOL;
}
The configuration file allows you to customize various aspects:
return [
// API Configuration
'api_token' => env('TREBLLE_OAAS_API_TOKEN'),
'base_url' => env('TREBLLE_OAAS_BASE_URL', 'https://api-forge.treblle.com/api/v1'),
// Request Timeouts
'timeout' => env('TREBLLE_OAAS_TIMEOUT', 30),
'connect_timeout' => env('TREBLLE_OAAS_CONNECT_TIMEOUT', 10),
// Pagination Defaults
'default_limit' => env('TREBLLE_OAAS_DEFAULT_LIMIT', 20),
'max_limit' => env('TREBLLE_OAAS_MAX_LIMIT', 50),
];
The SDK throws OaaSException
for API errors:
use Treblle\OaaS\Exceptions\OaaSException;
try {
$requests = TreblleOaaS::requests('workspace-id', 'api-id')
->whereCustomer('customer-123')
->get();
} catch (OaaSException $e) {
echo "API Error: {$e->getMessage()}" . PHP_EOL;
echo "HTTP Status: {$e->getCode()}" . PHP_EOL;
if ($e->hasResponse()) {
$responseData = $e->getResponseData();
echo "Response: " . json_encode($responseData) . PHP_EOL;
}
}
The SDK provides rich data models:
RequestCollection
- Collection of request summaries with paginationRequestSummary
- Summary information about a requestRequestDetails
- Complete request details including headers, body, compliance, etc.PaginationMeta
- Pagination metadataPaginationLinks
- Pagination navigation links
This package is open-sourced software licensed under the MIT license.
For support, please visit Treblle's documentation or contact [email protected].