Discussion about unpublished data coming through Sanity's API and how to filter it out.
12 replies
Last updated: May 26, 2022
M
Was anyone going to respond to this
user A
? đ€May 26, 2022, 5:38 PM
Yes, we aim to look at every thread thatâs posted and respond to as many as possible. Weâre only 2-3 hours into our workdays so we appreciate your patience. đ
May 26, 2022, 5:51 PM
M
Thanks
May 26, 2022, 5:52 PM
M
Any chance someone could take a look at this please?
Weâre having production issues due to
unpublished data coming through Sanityâs API.
I know yâall are busy, but itâs been hoursâŠ
đ
Weâre having production issues due to
unpublished data coming through Sanityâs API.
I know yâall are busy, but itâs been hoursâŠ
đ
May 26, 2022, 6:46 PM
I donât understand the relation between the screenshot and what seems to be the issue. If youâre using a token, youâll get drafts back from a fetch, so youâd need to include
&& !(_id in path("drafts.**"))in your filter.
May 26, 2022, 6:49 PM
M
I just thought that something that was âdeletedâ, and then somehow âcame backâ, might have caused the unpublished content to come back from the APIâŠ
Wasnât aware that drafts came back w/ queries.. what do you mean, âusing a tokenâ?
Wasnât aware that drafts came back w/ queries.. what do you mean, âusing a tokenâ?
May 26, 2022, 6:55 PM
M
is there anyway to get the published status of pieces of content in that response so we can just filter them out?
May 26, 2022, 6:56 PM
M
Ah.. so if I donât send the auth token, then those draft items are filtered out.
Got it.
Got it.
May 26, 2022, 7:10 PM
D
await sanity.fetch(`*[_type == "place" && !(_id in path("drafts.**"))]`)
May 26, 2022, 7:10 PM
M
Thank you
May 26, 2022, 7:10 PM
B
To your original question âWhich I wasnât expecting due to the fact that itâs âunpublishedâ. Is the API supposed to be returning _un_published content??â
The answer is yes, it will show whatever you have asked of, which by default is drafts as well as published documents. You would need to explicitly query for everything âwithout draftsâ as User showed above.
The answer is yes, it will show whatever you have asked of, which by default is drafts as well as published documents. You would need to explicitly query for everything âwithout draftsâ as User showed above.
May 26, 2022, 7:11 PM
B
To your original question âWhich I wasnât expecting due to the fact that itâs âunpublishedâ. Is the API supposed to be returning _un_published content??â
The answer is yes, it will show whatever you have asked of, which by default is drafts as well as published documents. You would need to explicitly query for everything âwithout draftsâ as User showed above.
The answer is yes, it will show whatever you have asked of, which by default is drafts as well as published documents. You would need to explicitly query for everything âwithout draftsâ as User showed above.
May 26, 2022, 7:11 PM
B
Whoops, just saw your response
user G
, thanks for popping in! đŻMay 26, 2022, 7:11 PM
Sanityâ build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.