Contentful logo

Contentful Community

Setting up Preview Page

I have a live blog ready. I am trying to set up Preview page for the posts, but I don’t understand how they work. How does contentful know what API to use when I have two API’s written (delivery/preview)? How do I specify certain API to be used?

… full of confusion

Help…! :slight_smile:

Hi @yeggy.seo,

Could you explain in a bit more detail how exactly you’re implementing this - are you using any of our SDKs? Usually, you can easily define in your client setup which of these APIs you should use in your application.

For example, if you’re using the JavaScript SDK, you can differentiate between CDA and CPA by setting the appropriate endpoint in your host property:

const contentful = require('contentful')
const client = contentful.createClient({
  space: 'developer_bookshelf',
  accessToken: 'preview_0b7f6x59a0',
  host: 'preview.contentful.com'
})

Hello @gabriel !

Thank you for getting back to me. I made it work just now. I am using gatsby, netlify, and contentful to make a blog! I used the SDK you posted and everything worked magically. I realized was overthinking before :slight_smile:

Thank you so much for helping! Very much appreciated :slight_smile:

Hey there @yeggy.seo ,

I’m using the exact same stack as you and am still a bit confused as to how to get the preview working. How did you get yours working using the example code provided by @gabriel?

Cheers!