I’m having trouble with
wix comments v2 api.
It said I can query the comments using resourceId , but in frontend, I’m using CMS dynamic page and don’t find any get resourceId api to filter the fetched comments.
What I tried,
I tried checking with Wix Location link but it’s different from the reosurceId,
Please note we retrieved the required appId from the following article in the documentation.
In the items returned by this method (representing each comment) you’ll see a field titled resourceIdwhich can be used to get comments associated to a particular dynamic item page path.
I got that part already, what I want is to filter the comment of current page. Can you provide any example for me? I need the frontend filter the result sent from backend using “contextId” or “resourceId”
I’ve tried filtering by current wixdataset’s _id but it’s being different. Here is my code,
//Frontend Filtering using current page's CMS item's _id to check if it's match with resourceId. But unfortunately it's not,
import wixLocation from 'wix-location';
import { queryCommentsForPage } from 'backend/commentsv2.web'; // adjust your backend file path
$w.onReady(function () {
console.log("=== DEBUG INFO ===");
console.log("Full URL:", wixLocation.url);
console.log("Path array:", wixLocation.path);
// Get the actual item ID from dataset
if ($w('#dynamicDataset')) {
$w('#dynamicDataset').onReady(() => {
const currentItem = $w('#dynamicDataset').getCurrentItem();
console.log("Dataset current item:", currentItem);
if (currentItem) {
const itemId = currentItem._id; // 75d550e2-3285-4d78-86d5-061ca572e869
console.log("Using item ID as resourceId:", itemId);
// Fetch comments for this specific page
queryCommentsForPage(itemId)
.then((response) => {
console.log("Comments response:", response);
if (response.error) {
console.error("Error fetching comments:", response.e);
} else if (response.items && response.items.length > 0) {
console.log("✅ SUCCESS! Found comments for this page");
displayComments(response.items);
} else {
console.log("❌ No comments found for this page yet");
}
})
.catch((error) => {
console.error("Error calling backend:", error);
});
}
});
} else {
console.log("❌ No dynamicDataset found");
}
});
// Function to display comments
function displayComments(comments) {
console.log(`Displaying ${comments.length} comments:`);
comments.forEach((comment, index) => {
console.log(`Comment ${index + 1}:`, {
id: comment._id,
author: comment.author?.name || 'Anonymous',
content: comment.content?.text || 'No content',
date: comment._createdDate,
resourceId: comment.resourceId
});
});
}
A user recently posted the solution to a similar problem, try going through their code and see if you can find something that points you in the right direction:
I tested your queryCommentsForPage() method and it works as expected.
I believe the error occurs when the item id is passed from the dataset (currentItem) into the method.
const currentItem = $w('#dynamicDataset').getCurrentItem();
console.log("Dataset current item:", currentItem);
At the moment it seems to be passing the item ids from the data passed to the dataset.
Verify that the resourceId you see in queryAllComments() for the associated item’s comment thread matches what is being passed into the queryCommentsForPage() method.