Contentful Preview API wrongly includes `sys.locale` on response
See original GitHub issueExpected Behavior
Contentful Preview API should be consistent with Contentful Delivery API in that when making a query such as:
const response = await contentful.getEntries({
content_type: 'navigation',
locale: '*',
include: 10,
limit: 1,
})
The entries shouldn’t include sys.locale
. This field shouldn’t exist when query is all locales. This has been working fine all the time and we’ve noticed that preview breaks for us today because we rely on sys.locale
to figure out the type of response (if fields are localized)
Actual Behavior
The Contentful Preview API is including the sys.locale
field when making a request with locale: '*'
.
This is an example response’s entry from Contentful Preview API with the above ☝️ query:
{
sys: {
space: { sys: [Object] },
type: 'Entry',
id: '********',
contentType: { sys: [Object] },
revision: 26,
createdAt: '2020-05-18T11:47:03.837Z',
updatedAt: '2020-06-05T15:23:52.346Z',
locale: 'en', // <<<<<<<<<< This shouldn't have been included (Delivery API doesn't include it)
environment: { sys: [Object] }
},
fields: {
title: { en: '*******' },
navigation: { de: [Object], en: [Object], fr: [Object], nl: [Object] },
footer: { de: [Object], en: [Object], fr: [Object], nl: [Object] }
}
}
Possible Solution
Remove the sys.locale
from entries when request query includes all locales locale: '*'
as it has been before … today 🙈 (not sure exactly when this was introduced but it worked before today). Luckily, Contentful Delivery API wasn’t broken so our site is still alive.
Steps to Reproduce
- Create a Contentful Model
- Create a few fields and mark them as localized
- Create an entry
- Use Contentful Preview API to make a request (use the query provided above ☝️)
- Check response’s entries’
sys.locale
Context
Our site allows to switch to a preview mode which basically just uses Contentful Preview API. After today, we no longer can access the preview version because we rely on sys.locale
on entries to figure out if the response has localized fields (For example, if query was with locale: '*'
or locale: 'en'
)
Environment
- Language Version: Node v12.16.2
- Package Manager Version: Yarn 1.22.4
- Operating System: MacOS, Linux (deployed to Vercel, not sure what Linux OS runs under)
- Package Version: contentful@7.14.4
- Which API are you using?: Delivery (works as expected) / Preview (fails as explained above)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
@gburgett I opened a ticket with Contentful support yesterday and today they let me know that this was fixed. I’m testing before sending a reply but so far it seems that all is working again for us. It’d be great if you could verify with your team.
As this seems fixed, I will close it for now. Feel free to open it again.