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 trustpilotVerified import paths — ran on the pinned version, not inferred.
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.
Update all API call responses to access the actual data payload via the `.data` property (e.g., `(await client.apiRequest(...)).data`).
Adopt TypeScript for better integration or ensure your JavaScript environment correctly transpiles ESM imports. Avoid `require()` for this package and use `import` statements.
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.
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;`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.