Discussion of an error in a Groq query using Sanity.io API v1, resolved by switching to v2021-03-25.

13 replies
Last updated: May 18, 2022
Hey there, tried this out but not sure why it's off for me
*[_type == 'article'] {
  ...,
    "numberOfCharacters": pt::text(articleRichText),
    "estimatedWordCount": round(length(pt::text(articleRichText)) / 5),
    "estimatedReadingTime": round(length(pt::text(articleRichText)) / 5 / 180)
}[0]
this is the error i get back in Vision, which is odd

expected '}' following object body

*[_type == 'article'] {
----------------------^^^^^^^^^^^^^^^^^^^^^

Line:   0
Column: 22
because if i leave this out... it works just fine? idk
May 18, 2022, 9:49 PM
What version of the API are you using?
May 18, 2022, 9:51 PM
v1!
May 18, 2022, 9:52 PM
if i switch to anything else, it doesn't fail but
May 18, 2022, 9:53 PM
That might be the issue! Maybe try changing to v2021-03-25?
May 18, 2022, 9:53 PM
hmm, ah ok.
May 18, 2022, 9:53 PM
Can you share the url Vision gives you for that query? I'll play around with it.
May 18, 2022, 9:55 PM
reading the docs for
pt::
, and I think i'm doing it right? basically i want to target the parent field that has the rich text right? https://www.sanity.io/docs/groq-functions#7a2e04177fe6
May 18, 2022, 9:55 PM
i'm unfortunately in local development atm
May 18, 2022, 9:56 PM
The url for it will be usable since your content is hosted by us, even when the Studio isn't deployed. After you click 'Fetch' you'll see the url above the results.
May 18, 2022, 9:59 PM
Ok got it ! It looks like you were passing
body
instead of
articleRichText
. I think the issue originally was the API version.
May 18, 2022, 10:04 PM
of course i did 😅 thank you
May 18, 2022, 10:06 PM
You're welcome!
May 18, 2022, 10:06 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?