laravel-g2 maintained by jeffersongoncalves

Laravel G2
A Laravel client for the G2 API. A fluent G2 facade groups the reviews, products, reports, competitors, categories, and tracking endpoints behind resource accessors, authenticates every request with a token header, and throws a G2Exception on a non-2xx response instead of returning a silent error array.
Features
- Reviews —
reviews()->list(),get() - Products —
products()->list(),get() - Reports —
reports()->list(),get() - Competitors —
competitors()->list() - Categories —
categories()->list(),get() - Tracking —
tracking()->visitors() - Thin by design — every method returns the raw decoded JSON:API response as an array, no DTOs
- Fails loud — a non-2xx response throws
G2Exceptioncarrying the API's error message and HTTP status code
Installation
composer require jeffersongoncalves/laravel-g2
Optionally publish the config file:
php artisan vendor:publish --tag="g2-config"
Configuration
Add to your .env:
G2_API_TOKEN=your-api-token
Request API access at https://data.g2.com/api/v1 to get your token.
Config Options
// config/g2.php
return [
'token' => env('G2_API_TOKEN'),
'base_url' => env('G2_BASE_URL', 'https://data.g2.com/api/v1'),
];
Usage
use JeffersonGoncalves\G2\Facades\G2;
use JeffersonGoncalves\G2\Exceptions\G2Exception;
Reviews
G2::reviews()->list(productId: '123', state: 'published', page: 1, perPage: 25);
G2::reviews()->get('456');
Products
G2::products()->list(name: 'laravel', page: 1, perPage: 25);
G2::products()->get('123');
Reports
G2::reports()->list(page: 1, perPage: 25);
G2::reports()->get('789');
Competitors
G2::competitors()->list(productId: '123', page: 1, perPage: 25);
Categories
G2::categories()->list(name: 'crm', page: 1, perPage: 25);
G2::categories()->get('321');
Tracking
G2::tracking()->visitors(startDate: '2026-01-01', endDate: '2026-01-31', page: 1, perPage: 25);
Handling errors
try {
$result = G2::products()->get('123');
} catch (G2Exception $e) {
// $e->getMessage() — the API's errors[0].detail/title, or the raw response body
// $e->statusCode — the HTTP status code returned by G2
}
Testing
composer test
Static Analysis
composer analyse
Code Formatting
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.