> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mercurjs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish, reject, and delete reviews in code

> Set a review's status with updateReviewWorkflow and remove it with deleteReviewWorkflow.

Moderate reviews from your own code when the Admin API doesn’t fit, for example to auto-publish high ratings or to reject reviews flagged by a spam filter. Moderation is an `updateReviewWorkflow` run that sets `status`, and removal is a `deleteReviewWorkflow` run that soft deletes the review.

**1. Set the status**

Run `updateReviewWorkflow` with the review id and the new status:

```ts title="src/api/admin/review-moderation/[id]/route.ts" {13-15} theme={null}
import type {
  AuthenticatedMedusaRequest,
  MedusaResponse,
} from "@medusajs/framework/http"
import { updateReviewWorkflow } from "@mercurjs/core/workflows"

type Body = { status: "published" | "rejected" }

export async function POST(
  req: AuthenticatedMedusaRequest<Body>,
  res: MedusaResponse
) {
  const { result } = await updateReviewWorkflow(req.scope).run({
    input: { id: req.params.id, status: req.body.status },
  })

  res.json({ review: result })
}
```

Routes under `/admin` require an authenticated admin user by default. The workflow returns the updated review.

**2. Delete a review**

Add a `DELETE` handler to the same file that runs `deleteReviewWorkflow` with the review id as its whole input:

```ts title="src/api/admin/review-moderation/[id]/route.ts" theme={null}
import { deleteReviewWorkflow } from "@mercurjs/core/workflows"

export async function DELETE(
  req: AuthenticatedMedusaRequest,
  res: MedusaResponse
) {
  await deleteReviewWorkflow(req.scope).run({ input: req.params.id })

  res.json({ id: req.params.id, object: "review", deleted: true })
}
```

The review gets a `deleted_at` timestamp. Its row and its four links stay in the database.

## Publish reviews automatically

Run the moderation from a subscriber to publish reviews without an operator. The module emits `review.review.created` with the new review’s id, so you can load the review and decide:

```ts title="src/subscribers/auto-publish-reviews.ts" theme={null}
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
import { MercurModules } from "@mercurjs/types"
import { updateReviewWorkflow } from "@mercurjs/core/workflows"

export default async function autoPublish({
  event,
  container,
}: SubscriberArgs<{ id: string }>) {
  const reviewService = container.resolve(MercurModules.REVIEW)
  const review = await reviewService.retrieveReview(event.data.id)

  if (review.rating >= 4) {
    await updateReviewWorkflow(container).run({
      input: { id: review.id, status: "published" },
    })
  }
}

export const config: SubscriberConfig = { event: "review.review.created" }
```

This publishes every review rated 4 or 5 and leaves the rest `pending` for an operator. See the [Events reference](https://docs.mercurjs.com/platform/review/reference/events.md) for the payload.

## Correct a review’s content

`updateReviewWorkflow` also accepts `rating`, `customer_note`, and `seller_note`. Use it to fix a rating, redact a note, or clear a store’s answer:

```ts theme={null}
await updateReviewWorkflow(container).run({
  input: { id: "rev_01JD8Q1234567", customer_note: null },
})
```

The workflow saves the previous `rating`, `customer_note`, `seller_note`, and `status` before it writes, and restores them if a later step fails.

## Account for soft deleted reviews in averages

A soft deleted review disappears from `query.graph` and the APIs, but the service’s rating helpers still count it, because their query doesn’t check `deleted_at`. Compute averages with `query.graph` if deletions must change the number, as shown in [Compute aggregate ratings](https://docs.mercurjs.com/platform/review/guides/compute-aggregate-ratings.md).

## Next steps

* [Let the store answer the review](https://docs.mercurjs.com/platform/review/guides/respond-to-a-review.md)
* [Learn which status changes are allowed](https://docs.mercurjs.com/platform/review/concepts/ratings-and-moderation.md)
* [Check updateReviewWorkflow’s input](https://docs.mercurjs.com/platform/review/reference/workflows.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.