When adding a value to your UID field, you may encounter an error when trying to save your page.
This could mean another page in your repository already has this UID value. It could be a page that is drafted or in the archive. If you can't find the page with this UID value, one of your pages used to have this UID value, and kept it stored in its history.
Each document in Prismic saves its history of UIDs. If a page once had the UID example-uid, it retains that UID until the page is deleted, even if that UID has been changed and is no longer currently example-uid. UIDs are preserved in the history of a page to prevent URLs from breaking. UIDs can be shared between different custom types. For example, a page type and a book type can both have a page with the UID example-uid. Translations of the same page can share the same UID since they are considered the same page in different languages.
This usually explains why you’re not able to re-use a UID that you can’t see being used anywhere.
Steps to Reuse a UID:
If you don’t know which document is storing example-uid, navigate to your API Explorer (replace your-repo-name with your repository’s name):
Change the request method to getByUID, select your document type, and enter the UID you’re looking for. The page associated with example-uid will be returned.
Duplicate the Page: Go to that page in your repository's Page Builder. Once you have it, duplicate it by going to the edit page and clicking the Duplicate button.
Delete the Original Page: After duplicating, delete the original page with the old UID. This will free up the example-uid for reuse.
But in my case, I use UIDs as the page paths.
And when I want to add a link in page (A) to point to page (B), I do that by linking the page documents internally (i.e. add a link in page A document pointing to page B document). So if I duplicate and delete the old document of page (B) all the links to page (B) in other documents will be broken.
Also, according to SEO, it is not recommended to have 2 urls serving the same content. Is there any way I can unlock the old UIDs to reuse them without deleting the old page document?
Hello @mahmoud.elbayoumy, Yes. If you delete a document you'd need to re-add the links where you used it. For the moment this is the only workaround to reuse an existing old UID.
Duplicating a document is making a copy of that sole document. Nothing else gets duplicated except that one. In the duplicated version, all content will be the same, including Links to other documents, but these are just references to those docs. It doesn’t mean they get duplicated as well.
We are already tracking it as a feature request for future improvement.
I'm in a situation where performing the above query returns one document but this document is not visible in my Prismic dashboard. What am I supposed to do to free up the UID in that case?
When I go to the document based on the ID, there is a mismatch between the route name and the UID value I want to use.
For future users that encounter this issue but can't find the document with that uid in the api:
For me, the document returned in in the API didn't have the same uid, but still walking through the steps above on that very document deleted the uid in question. It's like that document had 2 uids.
Hope this helps others that end up in this tricky spot!