Contentful logo

Contentful Community

Newlines are not encoded in content preview parameters

Hi Contentful team,

I am building a preview endpoint for our content, and would like to avoid having to have knowledge of the contentful API key on the preview host. As such, I tried to pass the body of our content type, which is markdown, as one of the query parameters to the preview endpoint, i.e. https://some_endpoint/path?body={entry.fields.body}

For the most part this worked, however newlines in the source document are not preserved, and are lost when added to the URI. For example:


This could be relatively easily fixed by adding the newline encoded URL character %0A, rather than stripping the newlines as seems to be the current case. So instead of the current situation yielding the URI https://some_endpoint/path?body=hello,world we’d get https://some_endpoint/path?body=hello,%0Aworld which could be correctly rendered.

We have a workaround for this at the moment, passing the entity ID instead and using the Contentful API to pull the article, however this requires us to use our API key, which we’d really like to avoid for security reasons.

Is there any chance we could get a fix like this made any time in the future?