Laravel Trustpilot
#Laravel Trustpilot
A Laravel client for the Trustpilot API. A fluent Trustpilot facade groups the business unit, review, reply, invitation, and tag endpoints behind resource accessors, picks the right credentials per call — the apikey header for public data, an OAuth bearer token for everything private — and throws a TrustpilotException on a non-2xx response instead of returning a silent error array.
#Features
- Business Units —
businessUnits()->search(),get(),profile(),categories(),webLinks() - Reviews —
reviews()->list(),get(),latest(),private(),reply(),deleteReply() - Invitations —
invitations()->create(),link(),templates() - Review Tags —
tags()->get(),add(),remove() - Both auth modes handled for you — public calls use the API key, private calls mint and cache a client-credentials bearer token until just before it expires
- Default business unit — set it once in the config and omit the id everywhere
- Thin by design — every method returns the raw decoded JSON response as an array, no DTOs
- Fails loud — a non-2xx response throws
TrustpilotExceptioncarrying the API's error message and HTTP status code
#Installation
composer require jeffersongoncalves/laravel-trustpilot
Optionally publish the config file:
php artisan vendor:publish --tag="trustpilot-config"
#Configuration
Add to your .env:
TRUSTPILOT_API_KEY=your-api-key TRUSTPILOT_API_SECRET=your-api-secret TRUSTPILOT_BUSINESS_UNIT_ID=your-business-unit-id
Create the application at the Trustpilot Business app. The secret is only needed for the private endpoints (private reviews, replies, invitations, tags) — leave it unset if you only read public data. Find your business unit id with Trustpilot::businessUnits()->search('example.com').
#Config Options
// config/trustpilot.php return [ 'api_key' => env('TRUSTPILOT_API_KEY'), 'api_secret' => env('TRUSTPILOT_API_SECRET'), 'business_unit_id' => env('TRUSTPILOT_BUSINESS_UNIT_ID'), 'base_url' => env('TRUSTPILOT_BASE_URL', 'https://api.trustpilot.com/v1'), 'cache_key' => env('TRUSTPILOT_CACHE_KEY', 'trustpilot.access_token'), ];
#Usage
use JeffersonGoncalves\Trustpilot\Facades\Trustpilot; use JeffersonGoncalves\Trustpilot\Exceptions\TrustpilotException;
Every method that takes a $businessUnitId falls back to trustpilot.business_unit_id when you omit it.
#Business Units
Trustpilot::businessUnits()->search('example.com', limit: 20); Trustpilot::businessUnits()->get(); Trustpilot::businessUnits()->profile(); Trustpilot::businessUnits()->categories(); Trustpilot::businessUnits()->webLinks('pt-BR');
#Reviews
Trustpilot::reviews()->list(perPage: 20, orderBy: 'createdat.desc', stars: 5, language: 'pt'); Trustpilot::reviews()->get('review-id'); Trustpilot::reviews()->latest(20); // private — needs TRUSTPILOT_API_SECRET Trustpilot::reviews()->private(perPage: 20, stars: 1); Trustpilot::reviews()->reply('review-id', 'Thanks for the feedback!'); Trustpilot::reviews()->deleteReply('review-id');
#Invitations
Trustpilot::invitations()->create('ada@example.com', 'Ada Lovelace', reference: 'order-42'); // extra payload keys go through `attributes` Trustpilot::invitations()->create('ada@example.com', 'Ada Lovelace', attributes: [ 'senderEmail' => 'noreply@example.com', 'replyTo' => 'support@example.com', 'templateId' => 'your-template-id', ]); Trustpilot::invitations()->link('ada@example.com', 'Ada Lovelace', reference: 'order-42'); Trustpilot::invitations()->templates();
#Review Tags
Trustpilot::tags()->get('review-id'); Trustpilot::tags()->add('review-id', 'topic', 'shipping'); Trustpilot::tags()->remove('review-id', 'topic', 'shipping');
#Handling errors
try { $reviews = Trustpilot::reviews()->list(); } catch (TrustpilotException $e) { // $e->getMessage() — the API's message/error_description, or the raw response body // $e->statusCode — the HTTP status code returned by Trustpilot (0 for config errors) }
#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.