I hope this message finds you well. I'm currently encountering an issue with the "@prismicio/client" npm package, specifically version "^7.3.1," and I could use some assistance in resolving it.
Goal: From a Webhook request, retrieving document to build url in order to invalidate nextJS page cache from path
Problem Description: When making requests using the getByID or getByIDs methods, I am consistently receiving empty documents as a response. I have verified that the Access Token and repository client values are correct, and I've confirmed that the IDs provided in the requests are valid.
Access Token and Repository Client values are correctly configured.
Checked and confirmed the correctness of the Access Token and Repository Client values.
Verified that the provided document IDs are valid.
Double-checked the ID yielded to the request, and it appears to be correct.
Attempted the request with different valid document IDs, still receiving empty documents.
Expected Outcome: I expect to receive the actual document data corresponding to the provided document IDs.
Actual Outcome: The requests consistently return empty documents or error from getByID
Node.js version: 18.19 (Latest as of [Current Date])
Operating System: MacOS 14.1.1
Note: This issue is hindering my development progress, and any assistance or insights you can provide would be greatly appreciated. If there are any additional details or logs needed, please let me know, and I'll be happy to provide them.
I'm using the getSingle method to fetch a document by its type, and the response is successful. However, when I attempt to retrieve the same document using its ID with the getByID method, the returned document is empty.
const response = await this.prismic.getSingle('template');
// Response is okay
const doc = await this.prismic.getByID(response.id);
// Document is empty
Despite using the document IDs provided by the webhook, the subsequent attempt to fetch the document using getByID still results in an empty document. I've noticed that the IDs I'm working with are UID values rather than traditional document IDs.
const webhookResponse = //... // The response from the webhook containing the 'documents' property
const documentID = webhookResponse.documents; // Using the first document ID from the list
const doc = await this.prismic.getByID(documentID);
// At this point, 'doc' is consistently empty
Could the usage of UID instead of ID be influencing this behavior? Any guidance on how to handle UIDs in this context would be highly appreciated.
I understand the code, I'm just trying to clarify because whatever you're passing as response.id is breaking the query in that case, unless no document exists.
The best way to see why it's not working is to console log response.id, then if it's anything other that an ID such as ZTtDgBIAAFAMojmh then your code is breaking down there.
If response is a variable which represents the webhook payload as described in the article below then you'll your code should be prismic.getByIDs(arrayOfIDs) since you're dealing with an array in the response, the array in this case would be response.documents, so prismic.getByIDs(response.documents)
But again if your goal is...
Then the method I linked to will most likely be more robust.