craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 57 forks source link

Feature Request: Support drafts and live preview with element api #43

Closed keithmancuso closed 7 years ago

keithmancuso commented 7 years ago

We are working on a site that's built in VueJs and loads all its data via the element api. The big downside that we have found is there doesn't seem to be a way to support sharable draft urls or live preview which is a big bummer for our clients

Would there be anyway to support the same sort of "token?=" params for the for the element api? We could do the work to handle the rest assuming there was some way to get the preview and/or draft data via the api

brandonkelly commented 7 years ago

Related to https://github.com/craftcms/cms/issues/1489

narration-sd commented 7 years ago

Definite support for the direction of this FR -- as ran into the same specific as @keithmancuso.

I'm thinking along the lines however of live preview tokens giving changed-element information that would allow js in the template to trigger a Vue event. This would handle the element api situation fully and efficiently, but also many more possible situations it seems clear.

Might this give some ideas for handling craftcms/cms#1489 and related as well?

Radiergummi commented 7 years ago

@keithmancuso have you found a solution to this? I'm in the exact same situation right now. I'm currently considering defining a new HTTP adapter in an inline script block that returns the current entry content for API requests, but that'd be a pretty hideous solution...

tylerbrostrom commented 7 years ago

TL;DR: "Gimme! Gimme! I want it! I want it!"

Craft is hands-down one of the most thoughtfully put together content authoring experiences out there. To me, choosing Craft is a no-brainer.

It is a bummer, though, that headless Craft doesn't support drafts and live preview. I want to use Craft for all the projects, but I also want to maintain the excellent authoring experience that is the mark of a traditional Craft project.

I have faith that as a headless CMS architecture becomes more and more standard, the great people behind Craft will answer. Thanks @brandonkelly for all of Pixel & Tonic's work. Sorry for complaining about the wifi!

brandonkelly commented 7 years ago

@bro-strummer You had me at the Louis CK link.

Just released Element API 2.5 for Craft 3, which supports entry drafts & versions.

(Live Preview support for drafts & versions will require craftcms/cms#1489, slated for 3.1.)

narration-sd commented 7 years ago

Well, now we know how to appeal...and that clip feels pretty relevant to a lot of things, doesn't it.

Happy to insta-report that Element API continues to work with some sufficiently wild things I'm doing with it, also.

narration-sd commented 7 years ago

p.s. Hoping same for #1489.

tylerbrostrom commented 7 years ago

Dreams do come true! Thanks @brandonkelly!

mattandrews commented 7 years ago

@brandonkelly thanks so much for your work on this! We really needed this feature, fantastic to see it go live! Really appreciate the work that went into this. 💯

spotd commented 6 years ago

Just seen that live preview support has been moved to 4.0 (#1489) ? I need live preview for a lot of react projects this year using element api. Is there any way around this?

narration-sd commented 6 years ago

@spotd Live Preview itself is present and working on Craft 3. I believe what's put off is support for it in Multisite cases.

I presume it would presently continue to work on the default site when there are others, if haven't tested that -- @brandonkelly can answer that intention. Is Multisite Live Preview what you need?

for React or Vue, though, Multisite or not, you'd need more than the built-in Live Prevue can deliver. I'm more than a little on that case, and it might be interesting to chat a little about React needs.

Can you DM me via @narration_sd on the Craft Slack, where emails can be exchanged to make a conversation comfortable?

dictions commented 5 years ago

@narration-sd do you have any info on getting a $draftId or $versionId` to the element API calls?

I can't find any docs on getting that info from the live preview token. Nor on the getting live preview entry data into the element API.

narration-sd commented 5 years ago

@dictions I just checked up above, and Brandon posted a link early to doc which should handle your $draftId etc., looks like...

https://github.com/craftcms/element-api#entry-drafts-and-versions

live preview in the element api would be a more recent case; not aware if it's implemented

chrishentges commented 4 years ago

Is this not a thing anymore? All of the documentation links don't lead to a section for drafts and versions.

Mmasson-01 commented 4 years ago

Is this not a thing anymore? All of the documentation links don't lead to a section for drafts and versions.

https://github.com/craftcms/element-api/tree/2.5.4

brandonkelly commented 3 years ago

The old draft/version support has been removed since Craft 3.2+ is capable of returning drafts and revisions via normal entry queries, using drafts, draftId, draftOf, revisions,revisionId, andrevisionOf` params.

xmarkclx commented 8 months ago

Hello everyone! I found out a way to support live previews with element API.

Just add token query string, that's it!

&token=xxxxx

Just posting here in case it will save people's time as it wasted a few of mine.