Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

trustpilot

trustpilot43.4kMIT4.0.1TypeScript support: included

HTTP client for Trustpilot

API, Trustpilot, reviews, review

readme

trustpilot

This a NodeJS API wrapper for accessing the Trustpilot APIs. You can learn all about the Trustpilot API at https://developers.trustpilot.com/.

Installation

This module is built using Typescript and NodeJS v20.x.

Install using npm install trustpilot

Usage

As of version 3, the project has been converted to Typescript. The trustpilot module is async/await based. It provides an axios instance with sane defaults.

Basic Usage

import { TrustpilotApi } from "trustpilot";

async run() {
  const client = new TrustpilotApi({
      key: 'YOUR-API-KEY',
      secret: 'YOUR-SECRET',
      username: 'YOUR-TRUSTPILOT-B2B-USERNAME',
      password: 'YOUR-TRUSTPILOT-B2B-PASSWORD',
      baseUrl: 'https://api.trustpilot.com'
    });

  // For basic calls authentified by API key, use client.apiRequest
  try {
    const response = await client.apiRequest('/v1/resources/images');
    console.log(response.data);
  } catch(error) {
    // handle the error
  });
}

Usage with OAuth

For calls authentified by OAuth token, use the authenticate() promise, which resolves with an axiosInstance object with everything you need.

import { TrustpilotApi } from "trustpilot";

async run() {
  const client = await new TrustpilotApi({
      key: 'YOUR-API-KEY',
      secret: 'YOUR-SECRET',
      username: 'YOUR-TRUSTPILOT-B2B-USERNAME',
      password: 'YOUR-TRUSTPILOT-B2B-PASSWORD',
      baseUrl: 'https://api.trustpilot.com'
    }).authenticate();

  try {
    const response = await client.get(`/v1/private/business-units/${YOUR_BUSINESS_UNIT_ID}/reviews`);
    console.log(response.data);
  } catch(error) {
    // handle the error
  });
}

Choose OAuth token grant type

For service-to-service communication use 'client_credentials' grant type and API application key, secret combination to obtain an OAuth token. (Default grant type: password)

import { TrustpilotApi } from "trustpilot";

async run() {
  const client = await new TrustpilotApi({
      key: 'YOUR-API-KEY',
      secret: 'YOUR-SECRET',
      grantType: 'client_credentials',
      baseUrl: 'https://api.trustpilot.com'
    }).authenticate();

  // Use client
}

Override API Base URL

The Invitations API methods have a different base URL. To override it, simply pass the baseUrl.

import { TrustpilotApi } from "trustpilot";

async run() {
  const client = await new TrustpilotApi({
      key: 'YOUR-API-KEY',
      secret: 'YOUR-SECRET',
      username: 'YOUR-TRUSTPILOT-B2B-USERNAME',
      password: 'YOUR-TRUSTPILOT-B2B-PASSWORD',
      baseUrl: 'https://invitations-api.trustpilot.com'
    }).authenticate();

  // Use client
}

Migration from v3 to v4

As of version 4, request-promise-native has been replaced by axios

This means all responses are now following this response schema so code that previously used the response body directly, will need to add a .data

const json = await client.apiRequest('...');
const json = (await client.apiRequest('...')).data;

changelog

4.0.1 (2024-04-17)

Bug Fixes

  • update readme to include base url (935c0e3)

4.0.0 (2024-04-17)

Bug Fixes

Features

  • refactor lib to use axios (16d7acf)

BREAKING CHANGES

  • replaces request-promise with axios

3.4.0 (2022-10-13)

New

  • Select OAuth grant type for authentication (03b6d5a)

Upgrade

  • Bump handlebars from 4.7.6 to 4.7.7 (2029977)

3.3.0 (2021-03-23)

Build

  • Attempting to fix build by disabling node_modules caching (73dd483)

Chore

New

  • Opportunity to provide custom connection management agent for the client (884004c)

Upgrade

  • Upgrade dependencies and fix vulnerabilities (c36bfe2)
  • Upgrade dependencies and fix vulnerabilities (71817c4)

3.2.0 (2019-06-19)

Chore

Update

3.1.2 (2019-05-01)

Build

Fix

Upgrade

3.1.1 (2019-01-21)

Fix

3.1.0 (2018-12-04)

Docs

New

3.0.0 (2018-12-03)

Breaking

Build