Reads approved customer reviews and submits new ones, via lynkow.reviews.

A submission is approved at once when its rating meets the site's auto-approval threshold, and waits for moderation otherwise. Submissions carry the honeypot and timestamp spam fields automatically.

Access via: lynkow.reviews

Methods

5 methods

clearCache

TypeScript
clearCache(): void

Clears every cached review response: lists, single reviews and settings. submit calls it after a successful submission. Call it after a moderation change, for example on a review.* webhook. Has no effect without cache: true.

Returns: void

TypeScript
// After an admin approved a pending review:
lynkow.reviews.clearCache()

getBySlug

TypeScript
getBySlug(slugOrId: string, options?: BaseRequestOptions): Promise<Review>

Fetches one approved review by its slug or its UUID. With cache: true, cached for 5 minutes per locale.

Throws LynkowError NOT_FOUND with apiCode RESOURCE_NOT_FOUND when no approved review matches, and without a request for an empty, . or .. value.

Parameter

Type

Description

slugOrId

string

The review's slug, e.g. 'excellent-service', or its UUID.

options

BaseRequestOptions

Request options: locale, fallback and fetchOptions.

Returns: Promise<Review>

TypeScript
const review = await lynkow.reviews.getBySlug('excellent-service')
console.log(review.rating)   // 5
console.log(review.content)  // "Best experience ever!"

list

TypeScript
list(filters?: ReviewsFilters, options?: BaseRequestOptions): Promise<ReviewsListResponse>

Lists approved reviews, newest first by default, 20 per page (at most 100). With cache: true, cached for 5 minutes per filter set.

meta.total counts the filtered set. meta.averageRating and meta.totalApproved cover every approved review in the served language, ignoring every other filter.

Throws LynkowError NOT_FOUND with apiCode PRODUCT_NOT_FOUND when product names no product published on the storefront, and VALIDATION_ERROR for an out-of-range limit or rating, or an unknown sort.

Parameter

Type

Description

filters

ReviewsFilters

page, limit, minRating, maxRating, sort, order, product and language. See ReviewsFilters.

options

BaseRequestOptions

Request options: locale, fallback and fetchOptions.

Returns: Promise<ReviewsListResponse>

TypeScript
const { data, meta } = await lynkow.reviews.list({
  minRating: 4,
  sort: 'rating',
  order: 'desc',
  limit: 10,
})
console.log(meta.averageRating, data.length)

settings

TypeScript
settings(options?: BaseRequestOptions): Promise<ReviewSettings>

Fetches what a review form needs: whether visitors may submit, whether an email is required, and the site's extra questions, labelled in the requested locale when translated. With cache: true, cached for 10 minutes per locale.

Parameter

Type

Description

options

BaseRequestOptions

Request options: locale and fetchOptions.

Returns: Promise<ReviewSettings>

TypeScript
const settings = await lynkow.reviews.settings()
if (!settings.publicSubmissionEnabled) {
  // Submissions are disabled, hide the form
  return
}
for (const field of settings.customFieldsSchema) {
  renderInput(field.id, field.label, field.type, field.required)
}

submit

TypeScript
submit(data: ReviewSubmitData, options?: TimedSubmitOptions & BaseRequestOptions): Promise<ReviewSubmitResponse>

Submits a review. Adds the spam fields _hp and _ts (the client's creation time, capped at 55 minutes ago, unless you pass formStartedAt) and the client locale when data.locale is absent. When the site uses reCAPTCHA, pass a v2 token or a v3 token with action review_submit. A review the spam filter flags resolves like an accepted one but is not stored. Sent once, never retried.

Throws LynkowError FORBIDDEN when the site refuses submissions, VALIDATION_ERROR for an invalid field or unknown productId, BAD_REQUEST with apiCode VALIDATION_FIELD_REQUIRED (missing required email), VALIDATION_FIELD_INVALID (locale not enabled), RATE_SUBMISSION_EXPIRED, SPAM_RECAPTCHA_REQUIRED or SPAM_RECAPTCHA_FAILED, and TOO_MANY_REQUESTS with RATE_SUBMISSION_TOO_FAST.

Parameter

Type

Description

data

ReviewSubmitData

The review: authorName, rating and content are required. See ReviewSubmitData.

options

TimedSubmitOptions & BaseRequestOptions

recaptchaToken, formStartedAt (see TimedSubmitOptions) and fetchOptions.

Returns: Promise<ReviewSubmitResponse>

TypeScript
const result = await lynkow.reviews.submit({
  authorName: 'Alice',
  rating: 5,
  content: 'Excellent service!'
})

if (result.status === 'pending') {
  // Show "your review is awaiting moderation"
} else {
  // result.status === 'approved': it is already live
}
console.log(result.id) // UUID of the new review