Document ID different from the one webhook sent

Hey guys,

I have one bug I can't wrap my head around. I use the webhook feature to notify my Next.js API route when a new article is published in prismic (I send newsletters when a new article is added, containing the link to the new article). The webhooks sends the id of the new document, and then using the prismic/client (v7.4.1) I fetch the document using the getByType function.

const article = await prismicClient.getByType("article", {
    filters: [filter.at("document.id", body.documents[0])],
  });

However this returns no results. When I fetch the article by it's UID I see that its ID is different than what the Webhook sent.

Thanks in advance

Hi Amar,

Are you maybe confusing UID and ID? These are 2 different fields.

In Prismic, ID and UID are two different fields used for distinct purposes in content management:

1. Prismic ID:

  • System-generated: Every document in Prismic has a unique ID that is automatically generated by the system.
  • Immutable: Once assigned, it never changes, even if the content or document is updated.
  • Purpose: It’s used internally by Prismic to reference and track documents in the API, databases, and across the Prismic infrastructure.
  • Usage: Typically used by developers when working with Prismic's API for querying specific documents or managing content programmatically.

2. UID (Unique Identifier):

  • User-defined: The UID is a human-readable string that can be set by content editors. It’s meant to create a unique identifier that is more meaningful and relevant to the content.
  • Mutable: Editors can update the UID, and this change will affect how the document is accessed via URL or Prismic’s API.
  • Purpose: Commonly used to build SEO-friendly URLs (i.e., slugs), making it easier to locate and link to content.
  • Usage: Often included in dynamic routes of websites (e.g., /blog/my-article where my-article is the UID).

In summary:

  • ID: Auto-generated by Prismic, used for internal references.
  • UID: User-generated, used for URLs and content identification in a readable format.

This distinction is important in cases where the content's public-facing identity (via UID) may change, while the underlying document's system ID remains constant.