# Planned preview error

**URL:** <https://community.prismic.io/t/planned-preview-error/17898>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [October 29, 2024, 8:46am UTC](https://community.prismic.io/t/planned-preview-error/17898 "2024-10-29T08:46:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prismic5](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/prismic5/32/1790_2.png) [@prismic5](https://community.prismic.io/u/prismic5)\
**Post date:** [October 29, 2024, 8:46am UTC](https://community.prismic.io/t/planned-preview-error/17898/1 "2024-10-29T08:46:01Z")

</div>

Trying to preview planned release after latest prismic upgrade doesn't return any token to check against the prismic sdk.  
So no way to see any planned changes.

---

<div class="post-metadata">

**Author:** ![Ezekiel](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@Ezekiel](https://community.prismic.io/u/Ezekiel)\
**Post date:** [October 29, 2024, 9:44am UTC](https://community.prismic.io/t/planned-preview-error/17898/2 "2024-10-29T09:44:54Z")

</div>

Hi @prismic5,

Could you share a little bit more information on the context of the issue you're encountering? How is your preview set up?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![prismic5](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/prismic5/32/1790_2.png) [@prismic5](https://community.prismic.io/u/prismic5)\
**Post date:** [October 29, 2024, 11:28am UTC](https://community.prismic.io/t/planned-preview-error/17898/3 "2024-10-29T11:28:03Z")

</div>

sure  
I have a api/preview route in next.js project

Here is the code in that api route

```auto
import { NextApiRequest, NextApiResponse } from 'next';

import { prismicClient } from 'api/prismic';
import { linkResolver } from 'utils/linkResolver';
import { getStringFromQueryString } from 'utils/querystring';

export default async function preview(req: NextApiRequest, res: NextApiResponse) {
  const ref = getStringFromQueryString(req.query.token);
  const documentId = getStringFromQueryString(req.query.documentId);

  if (!prismicClient) {
    return null;
  }

  if (!ref) {
    return res.status(401).json({ message: 'Missing ref from querystring' });
  }

  // Check the token parameter against the Prismic SDK
  const url = await prismicClient.resolvePreviewURL({
    linkResolver,
    previewToken: ref,
    documentID: documentId,
    defaultURL: '/',
  });

  if (!url) {
    return res.status(401).json({ message: 'Invalid token' });
  }

  // Enable Preview Mode by setting the cookies
  res.setPreviewData({
    ref, // pass the ref to pages so that they can fetch the draft ref
  });

  // Redirect the user to the share endpoint from same origin. This is
  // necessary due to a Chrome bug:
  // https://bugs.chromium.org/p/chromium/issues/detail?id=696204
  res.writeHead(200, { 'Content-Type': 'text/html; charset=UTF-8' });
  res.write(
    `<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; url=${url}" />
      <script>window.location.href = '${url}'</script>
      </head>`
  );

  res.end();
}

```

The issue is that I get the 401 message Missing ref from querystring and req.query returns emtpy object.

---

<div class="post-metadata">

**Author:** ![Ezekiel](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@Ezekiel](https://community.prismic.io/u/Ezekiel)\
**Post date:** [October 29, 2024, 11:55am UTC](https://community.prismic.io/t/planned-preview-error/17898/5 "2024-10-29T11:55:18Z")

</div>

Thank you for sharing 🙂 What version of Next are you using?

---

<div class="post-metadata">

**Author:** ![prismic5](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/prismic5/32/1790_2.png) [@prismic5](https://community.prismic.io/u/prismic5)\
**Post date:** [October 30, 2024, 8:04am UTC](https://community.prismic.io/t/planned-preview-error/17898/6 "2024-10-30T08:04:28Z")

</div>

Next 14

---

<div class="post-metadata">

**Author:** ![prismic5](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/prismic5/32/1790_2.png) [@prismic5](https://community.prismic.io/u/prismic5)\
**Post date:** [October 31, 2024, 10:17am UTC](https://community.prismic.io/t/planned-preview-error/17898/7 "2024-10-31T10:17:01Z")

</div>

any news @Ezekiel ?

---

<div class="post-metadata">

**Author:** ![Ezekiel](https://avatars.discourse-cdn.com/v4/letter/e/848f3c/32.png) [@Ezekiel](https://community.prismic.io/u/Ezekiel)\
**Post date:** [October 31, 2024, 4:25pm UTC](https://community.prismic.io/t/planned-preview-error/17898/8 "2024-10-31T16:25:06Z")

</div>

What latest prismic upgrade are you referring to? And is this issue specific to planned releases, i.e. everything else you're trying to preview works fine as is?

---

<div class="post-metadata">

**Author:** ![prismic5](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/prismic5/32/1790_2.png) [@prismic5](https://community.prismic.io/u/prismic5)\
**Post date:** [November 19, 2024, 3:48pm UTC](https://community.prismic.io/t/planned-preview-error/17898/9 "2024-11-19T15:48:20Z")

</div>

@Ezekiel  
Sorry for late response, I failed to hit reply last time around.

But what I mean with prismic upgrade is that recently the dashboard UI changed a lot. After that change we have been having trouble with preview on planned releses.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 19, 2024, 3:56pm UTC](https://community.prismic.io/t/planned-preview-error/17898/11 "2024-11-19T15:56:08Z")

</div>

@prismic5 Looks like you have a custom preview route, your preview route should be set up like this if you're following the recommended set up:

> <https://github.com/prismicio-community/nextjs-starter-prismic-multi-page/blob/33856459a927206a19765987d54f6812762e3ff9/src/app/api/preview/route.ts>

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 19, 2024, 3:58pm UTC](https://community.prismic.io/t/planned-preview-error/17898/12 "2024-11-19T15:58:02Z")

</div>

Your client should be set up like so:

> <https://github.com/prismicio-community/nextjs-starter-prismic-multi-page/blob/33856459a927206a19765987d54f6812762e3ff9/src/prismicio.ts#L27>
