Recenze
Ziskani schvalenych recenzi projektu.
Opravneni
Tento endpoint vyzaduje API klic s opravnenim Media.
GET /:slug/reviews
Vrati seznam schvalenych a viditelnych recenzi.
Pozadavek
curl -X GET \
-H "X-API-Key: vas_api_klic" \
https://api.zarezervujto.cz/api/v1/vas-projekt/reviews
Query parametry
| Parametr | Typ | Vychozi | Popis |
|---|---|---|---|
limit | number | 20 | Max pocet recenzi (max 50) |
offset | number | 0 | Pocet preskocit (strankovani) |
Odpoved
{
"success": true,
"count": 10,
"total": 45,
"averageRating": 4.6,
"totalReviews": 45,
"reviews": [
{
"id": "review-1",
"customerName": "Jan N.",
"rating": 5,
"comment": "Skvělá restaurace, výborné jídlo a příjemná obsluha. Určitě doporučuji!",
"businessReply": "Děkujeme za krásnou recenzi! Těšíme se na vaši další návštěvu.",
"repliedAt": "2024-12-10T15:00:00Z",
"createdAt": "2024-12-08T18:30:00Z"
},
{
"id": "review-2",
"customerName": "Marie K.",
"rating": 4,
"comment": "Velmi dobré jídlo, jen trochu delší čekání.",
"businessReply": null,
"repliedAt": null,
"createdAt": "2024-12-05T20:15:00Z"
}
]
}
Popis poli
Souhrn
| Pole | Typ | Popis |
|---|---|---|
count | number | Pocet recenzi v odpovedi |
total | number | Celkovy pocet recenzi |
averageRating | number | null | Prumerne hodnoceni (1-5) |
totalReviews | number | Pocet recenzi pro vypocet prumeru |
Recenze
| Pole | Typ | Popis |
|---|---|---|
id | string | Unikatni ID recenze |
customerName | string | Jmeno zakaznika |
rating | number | Hodnoceni (1-5 hvezd) |
comment | string | null | Text recenze |
businessReply | string | null | Odpoved firmy |
repliedAt | string | null | Datum odpovedi |
createdAt | string | Datum vytvoreni |
Priklad pouziti
async function getReviews(slug, apiKey, options = {}) {
const params = new URLSearchParams();
if (options.limit) params.append('limit', options.limit);
if (options.offset) params.append('offset', options.offset);
const response = await fetch(
`https://api.zarezervujto.cz/api/v1/$:slug/reviews?${params}`,
{
headers: { 'X-API-Key': apiKey }
}
);
return response.json();
}
// Pouziti
const data = await getReviews('restaurace-u-jana', 'zrt_live_...');
console.log(`Prumerne hodnoceni: ${data.averageRating} (${data.totalReviews} recenzi)`);
data.reviews.forEach(review => {
console.log(`${'⭐'.repeat(review.rating)} - ${review.customerName}`);
if (review.comment) console.log(` "${review.comment}"`);
});
Zobrazeni recenzi (React)
function ReviewCard({ review }) {
return (
<div className="border rounded-lg p-4 mb-4">
<div className="flex items-center justify-between mb-2">
<span className="font-medium">{review.customerName}</span>
<div className="flex">
{[1, 2, 3, 4, 5].map(star => (
<span
key={star}
className={star <= review.rating ? 'text-yellow-400' : 'text-gray-300'}
>
★
</span>
))}
</div>
</div>
{review.comment && (
<p className="text-gray-700 mb-3">{review.comment}</p>
)}
{review.businessReply && (
<div className="bg-gray-50 rounded p-3 mt-3">
<p className="text-sm text-gray-500 mb-1">Odpoved provozovatele:</p>
<p className="text-gray-700">{review.businessReply}</p>
</div>
)}
<p className="text-xs text-gray-400 mt-2">
{new Date(review.createdAt).toLocaleDateString('cs-CZ')}
</p>
</div>
);
}
function ReviewsSummary({ averageRating, totalReviews }) {
return (
<div className="flex items-center gap-4 mb-6">
<div className="text-4xl font-bold">{averageRating?.toFixed(1) || '-'}</div>
<div>
<div className="flex text-yellow-400 text-xl">
{[1, 2, 3, 4, 5].map(star => (
<span key={star} className={star <= Math.round(averageRating || 0) ? '' : 'text-gray-300'}>
★
</span>
))}
</div>
<p className="text-gray-500">{totalReviews} recenzi</p>
</div>
</div>
);
}
Strankovani
async function getAllReviews(slug, apiKey) {
const allReviews = [];
let offset = 0;
const limit = 50;
while (true) {
const data = await getReviews(slug, apiKey, { limit, offset });
allReviews.push(...data.reviews);
if (allReviews.length >= data.total) break;
offset += limit;
}
return {
reviews: allReviews,
averageRating: data.averageRating,
totalReviews: data.totalReviews
};
}
Chybove odpovedi
403 Permission Denied
{
"error": "Forbidden",
"message": "API key does not have media read permission",
"code": "PERMISSION_DENIED"
}
Reseni: Povolte opravneni Media pro vas API klic v nastaveni projektu.