mattmilburn / strapi-plugin-preview-button

A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view.
MIT License
100 stars 35 forks source link

Getting 404 when trying to hit the API endpoint #93

Closed bart-iimpcoll closed 1 year ago

bart-iimpcoll commented 1 year ago

Hello!

This is my setup in plugins.ts:

'preview-button': {
    config: {
      contentTypes: [
        {
          uid: 'api::content.content',
          draft: {
            url: 'http://localhost:1337/api/preview',
            query: {
              type: 'content',
              slug: '{slug}',
            },
          },
        },
      ],
    },
  },

but trying to reach the unpublished article with slug: fasdfasdf at the link http://localhost:1337/api/preview?type=content&slug=fasdfasdf gives me 404. How to get the JSON response from Strapi for the drafts of type content?

My local server runs on http://localhost:1337

Env info │ Time │ Thu Jun 29 2023 16:42:50 GMT+0200 (Central Euro… │ │ Launched in │ 682 ms │ │ Environment │ development │ │ Process PID │ 80393 │ │ Version │ 4.11.1 (node v18.15.0) │ │ Edition │ Community │ │ Database │ sqlite

bart-iimpcoll commented 1 year ago

After more research I figured out that the correct way to request will be http://localhost:1337/api/contents?publicationState=preview

wangfan002 commented 6 months ago

Hello How did you solve this problem? I encountered the same problem.

bart-iimpcoll commented 6 months ago

I added publicationState=preview to my API call