Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import trustpilot from "../../trustpilot.app.mjs";
import { makeRequest } from "../../common/api-client.mjs";
import { ENDPOINTS } from "../../common/constants.mjs";
import {
buildUrl,
parseProductReview,
validateReviewId,
} from "../../common/utils.mjs";

export default {
key: "trustpilot-fetch-product-review-by-id",
name: "Fetch Product Review by ID",
description: "Retrieves detailed information about a specific product review on Trustpilot. Use this action to get comprehensive data about a single product review, including customer feedback, star rating, review text, and metadata. Perfect for analyzing individual customer experiences, responding to specific feedback, or integrating review data into your customer service workflows. [See the documentation](https://developers.trustpilot.com/product-reviews-api#get-private-product-review)",
version: "0.0.3",
version: "0.1.0",
type: "action",
props: {
trustpilot,
Expand All @@ -18,11 +25,28 @@ export default {
async run({ $ }) {
const { reviewId } = this;

// Validate required parameters
if (!reviewId) {
throw new Error("Review ID is required");
}
if (!validateReviewId(reviewId)) {
throw new Error("Invalid review ID format");
}

try {
const review = await this.trustpilot.getProductReviewById({
// Build the endpoint URL
const endpoint = buildUrl(ENDPOINTS.PRIVATE_PRODUCT_REVIEW_BY_ID, {
reviewId,
});

// Make the API request
const response = await makeRequest($, this.trustpilot, {
endpoint,
});

// Parse the product review with the correct parser
const review = parseProductReview(response);

$.export("$summary", `Successfully fetched product review ${reviewId}`);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import trustpilot from "../../trustpilot.app.mjs";
export default {
key: "trustpilot-fetch-product-reviews",
name: "Fetch Product Reviews",
description: "Retrieves a list of product reviews for a specific business unit on Trustpilot. This action enables you to fetch multiple product reviews with powerful filtering options including star ratings, language, tags, and sorting preferences. Ideal for monitoring product feedback trends, generating reports, analyzing customer sentiment across your product catalog, or building review dashboards. Supports pagination for handling large review volumes. [See the documentation](https://developers.trustpilot.com/product-reviews-api#get-private-product-reviews)",
version: "0.0.3",
description: "Retrieves a list of product reviews for a specific business unit. See documentation [here](https://developers.trustpilot.com/product-reviews-api/#get-private-product-reviews)",
version: "1.0.0",
type: "action",
props: {
trustpilot,
Expand All @@ -14,96 +14,69 @@ export default {
"businessUnitId",
],
},
stars: {
page: {
propDefinition: [
trustpilot,
"stars",
"page",
],
},
sortBy: {
perPage: {
propDefinition: [
trustpilot,
"sortBy",
"perPage",
],
},
limit: {
sku: {
propDefinition: [
trustpilot,
"limit",
"sku",
],
},
includeReportedReviews: {
language: {
propDefinition: [
trustpilot,
"includeReportedReviews",
"language",
],
},
tags: {
state: {
propDefinition: [
trustpilot,
"tags",
"state",
],
},
language: {
locale: {
propDefinition: [
trustpilot,
"language",
"locale",
],
},
offset: {
type: "integer",
label: "Offset",
description: "Number of results to skip (for pagination)",
min: 0,
default: 0,
optional: true,
},
},
async run({ $ }) {
const {
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
page,
perPage,
sku,
language,
offset,
state,
locale,
} = this;

try {
const result = await this.trustpilot.getProductReviews({
// Use the shared method from the app
const result = await this.trustpilot.fetchProductReviews($, {
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
page,
perPage,
sku,
language,
offset,
state,
locale,
});

const {
reviews, pagination,
} = result;

$.export("$summary", `Successfully fetched ${reviews.length} product review(s) for business unit ${businessUnitId}`);
$.export("$summary", `Successfully fetched ${result.reviews.length} product review(s) for business unit ${businessUnitId}`);

return {
reviews,
pagination,
metadata: {
businessUnitId,
filters: {
stars,
sortBy,
includeReportedReviews,
tags,
language,
},
requestTime: new Date().toISOString(),
},
};
return result;
} catch (error) {
throw new Error(`Failed to fetch product reviews: ${error.message}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import trustpilot from "../../trustpilot.app.mjs";
import { makeRequest } from "../../common/api-client.mjs";
import { ENDPOINTS } from "../../common/constants.mjs";
import {
buildUrl,
parseServiceReview,
validateReviewId,
} from "../../common/utils.mjs";

export default {
key: "trustpilot-fetch-service-review-by-id",
name: "Fetch Service Review by ID",
description: "Retrieves detailed information about a specific service review for your business on Trustpilot. Use this action to access comprehensive data about an individual service review, including the customer's rating, review content, date, and any responses. Essential for customer service teams to analyze specific feedback, track review history, or integrate individual review data into CRM systems and support tickets. [See the documentation](https://developers.trustpilot.com/business-units-api#get-business-unit-review)",
version: "0.0.3",
description: "Get a private service review by ID, including customer email and order ID. Access comprehensive data about an individual service review for your business. [See the documentation](https://developers.trustpilot.com/business-units-api#get-private-review-by-id)",
version: "0.1.0",
type: "action",
props: {
trustpilot,
businessUnitId: {
propDefinition: [
trustpilot,
"businessUnitId",
],
},
reviewId: {
propDefinition: [
trustpilot,
Expand All @@ -22,23 +23,35 @@ export default {
},
},
async run({ $ }) {
const {
businessUnitId,
reviewId,
} = this;
const { reviewId } = this;

// Validate required parameters
if (!reviewId) {
throw new Error("Review ID is required");
}
if (!validateReviewId(reviewId)) {
throw new Error("Invalid review ID format");
}

try {
const review = await this.trustpilot.getServiceReviewById({
businessUnitId,
// Build the endpoint URL for private service review
const endpoint = buildUrl(ENDPOINTS.SERVICE_REVIEW_BY_ID, {
reviewId,
});

$.export("$summary", `Successfully fetched service review ${reviewId} for business unit ${businessUnitId}`);
// Make the API request
const response = await makeRequest($, this.trustpilot, {
endpoint,
});

// Parse the service review with the correct parser
const review = parseServiceReview(response);

$.export("$summary", `Successfully fetched service review ${reviewId}`);

return {
review,
metadata: {
businessUnitId,
reviewId,
requestTime: new Date().toISOString(),
},
Expand Down
Loading
Loading