Registry / http-networking / trustpilot

trustpilot

JSON →
library10.0.1jsnpmunverified

The `trustpilot` package is an official Node.js HTTP client for interacting with the Trustpilot APIs. Currently stable at version 4.0.1, released in April 2024, it provides a structured and type-safe way to access Trustpilot's data, including business reviews and company profile information. Built with TypeScript and leveraging `axios` for HTTP requests, it offers a modern promise-based interface with async/await support, targeting Node.js `v20.x`. Key differentiators include built-in support for both API key and OAuth-based authentication, with the flexibility to specify different OAuth grant types (e.g., `client_credentials` for service-to-service communication). The release cadence is generally infrequent, with major versions (like v3 and v4) typically driven by significant architectural changes, such as the underlying HTTP client library. It abstracts away much of the complexity of direct API interactions, providing a client instance with sane defaults.

npm install trustpilot
INSTALL
IMPORT
SIG · TRUSTPILOT
T
trustpilot
http-networkingjavascriptv10.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TrustpilotApi
import { TrustpilotApi } from 'trustpilot';
const { TrustpilotApi } = require('trustpilot');
The library was converted to TypeScript in v3 and is primarily designed for ESM usage. While CommonJS might technically work with transpilation, direct `require` is not the idiomatic approach for modern Node.js development with this package.

This quickstart demonstrates initializing the Trustpilot API client, making a basic API key authenticated request, and an OAuth authenticated request to fetch data, including handling potential errors.

import { TrustpilotApi } from 'trustpilot'; async function main() { const client = new TrustpilotApi({ key: process.env.TRUSTPILOT_API_KEY ?? '', secret: process.env.TRUSTPILOT_SECRET ?? '', username: process.env.TRUSTPILOT_B2B_USERNAME ?? '', password: process.env.TRUSTPILOT_B2B_PASSWORD ?? '', baseUrl: 'https://api.trustpilot.com' }); try { // Example 1: Basic call using API key authentication (client.apiRequest) console.log('Fetching image resources with API key...'); const apiResponse = await client.apiRequest('/v1/resources/images'); console.log('API Key Response Data:', apiResponse.data); // Example 2: OAuth-authenticated call (client.authenticate() returns axios instance) console.log('\nAuthenticating with OAuth...'); const oauthClient = await new TrustpilotApi({ key: process.env.TRUSTPILOT_API_KEY ?? '', secret: process.env.TRUSTPILOT_SECRET ?? '', username: process.env.TRUSTPILOT_B2B_USERNAME ?? '', password: process.env.TRUSTPILOT_B2B_PASSWORD ?? '', baseUrl: 'https://api.trustpilot.com' }).authenticate(); const businessUnitId = process.env.TRUSTPILOT_BUSINESS_UNIT_ID ?? 'YOUR_BUSINESS_UNIT_ID'; if (businessUnitId === 'YOUR_BUSINESS_UNIT_ID') { console.warn('WARNING: Replace YOUR_BUSINESS_UNIT_ID with an actual ID for the OAuth example to work.'); } const oauthResponse = await oauthClient.get(`/v1/private/business-units/${businessUnitId}/reviews`); console.log('OAuth Response Data:', oauthResponse.data); } catch (error: any) { console.error('An error occurred:', error.response?.data || error.message); } } main().catch(console.error);
Debug
Known issues
breakingVersion 4.0.0 replaced `request-promise-native` with `axios` as the underlying HTTP client. This changes the response schema; direct access to the response body now requires `.data`.
fix
Update all API call responses to access the actual data payload via the `.data` property (e.g., `(await client.apiRequest(...)).data`).
affects: >=4.0.0
breakingVersion 3.0.0 converted the entire library to TypeScript. This introduced type safety and modern JavaScript patterns, but may require changes to existing JavaScript codebases or build processes.
fix
Adopt TypeScript for better integration or ensure your JavaScript environment correctly transpiles ESM imports. Avoid `require()` for this package and use `import` statements.
affects: >=3.0.0
gotchaThe default OAuth grant type is 'password'. For service-to-service communication, it's often more appropriate and secure to use the 'client_credentials' grant type.
fix
When initializing `TrustpilotApi` for OAuth, explicitly set `grantType: 'client_credentials'` in the constructor options if you are performing server-to-server authentication without a user context.
affects: >=3.4.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'data')
Attempting to access the response directly after upgrading to v4, without using the `.data` property, after the switch from `request-promise-native` to `axios`.
fix
Ensure that after any `await client.apiRequest()` or `await oauthClient.get()`, you access the actual response body through `.data`. For example, `const result = (await client.apiRequest('/path')).data;`
ReferenceError: require is not defined in ES module scope
Using CommonJS `require()` syntax for the `trustpilot` package in a Node.js project configured as an ES module, or when running newer Node.js versions where ESM is preferred, after the library's conversion to TypeScript in v3.
fix
Switch to ES module `import` syntax: `import { TrustpilotApi } from 'trustpilot';`. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extension for ES modules.
Upgrade
Version history
10.0.1latest on npm
Audit
Dependencies
axiosrequiredCore HTTP client for making API requests, replaced `request-promise-native` in v4.
Agent activity
29 hits · last 30 days
node
28
OpenAI (training)
1
Resources
trustpilot — npm install trustpilot · libregistry