Get all old UIDs associated with a given document

I saw this other post asking if it's possible to get a list of all old UIDs for a given document. The response said no. It's not clear to me whether that post was to do with the old API or the GraphQL API.

Ideally I'd want to do this with the GraphQL API. Is there any way to do it? I want to have the full list of redirections available at static build time. I could query Prismic for the document associated with the UID given by the user at request time but I'd rather not take this route.

Use case: I want to redirect old UIDs to the new one.

Hey Bart, thanks for reaching out!

What did you meant with the old API?
You'll get the same response in both the REST API and GraphQL.

And to be able to redirect old UIDs to the new one you'll need to do a check. Please take a look at the response in this similar thread:

Unfortunately for statically generated websites, checking if the requested uid matches the current uid is not a valid solution. In this case we would need to be able to have the old uids in the API response as well and manually create redirects.

What we did for now is setting up a custom old uid field that we need to manually update if we eventually change an uid. It is not ideal but it works.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

That's not really a suitable solution, I think. A UID can change more than once, and requiring the content editor to remember to enter those old UIDs into a custom field will not be at all reliable.

The one you call the REST API.

As Romain said, it's not a good solution for statically generated websites.

So then this is now a feature request:

Please expose the list of old UIDs as part of the document metadata available for querying via the GraphQL API. You already provide an array of the document's tags; it shouldn't be tricky to also provide an array of the document's UIDs.

This would enable a full list of redirections to be put together at site build time, which is a speed boost for the visitor. It also means that 404s don't need to hit your API with requests, which ought to be a win for you too.

1 Like

Thank you for the feedback. I added this conversation as an open feature request since, for the moment, there's still no option no perform a similar query.

1 Like

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.