πŸ‘€ See Sanity in action: Watch product demo now β†’

GROQ Error - 'Unknown Query Parameter "Slug.Current"'

11 replies
Last updated: Apr 28, 2021
Hello folks! πŸ‘‹ I've finally had the chance to try Sanity out. GROQ seems really powerful but i'm having a strange issue with it.
When using the simple query *[ _type == "post" && slug.current == "${slug}"] i get the following error:

error: {
description: 'Unknown query parameter "slug.current"',
names: [ 'slug.current' ],
type: 'httpUnknownQueryStringParameters'
}

I've double checked in Vision that the query does work over there and that this is the correct key. Using just [ _type == "post"] works fine.

Any guidance in the right direction is very much appreciated, thank you!
Apr 28, 2021, 3:24 PM
I think you should rewrite it without quotes, like this:
*[ _type == "post" && slug.current == $slug]
Apr 28, 2021, 3:31 PM
Appreciate the answer. It didn't work for me. But I found a solution, I had to encode the query with encodeURIComponent. After this it worked!
Apr 28, 2021, 3:34 PM
Are you sending out a raw query? Or through the API client? I believe the API client would take care of that automatically.
Apr 28, 2021, 3:35 PM
It's a raw query through fetch. I think you might be right.
Apr 28, 2021, 3:36 PM
Ah, that explains it then! And also the difference in syntax (js. interpolation vs. GROQ params passed to the
client.fetch
method).
Apr 28, 2021, 3:37 PM
I'm gonna have to checkout the API client, didn't know it existed. Thanks a lot man!
Apr 28, 2021, 3:40 PM
Appreciate the answer. It didn't work for me. But I found a solution, I had to encode the query with encodeURIComponent. After this it worked!
Apr 28, 2021, 3:34 PM
Are you sending out a raw query? Or through the API client? I believe the API client would take care of that automatically.
Apr 28, 2021, 3:35 PM
It's a raw query through fetch. I think you might be right.
Apr 28, 2021, 3:36 PM
Ah, that explains it then! And also the difference in syntax (js. interpolation vs. GROQ params passed to the
client.fetch
method).
Apr 28, 2021, 3:37 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in