Specifications

GROQ parameters

How to pass parameters to GROQ queries

Parameters are client-provided values that are substituted into queries before execution. Their names must begin with $ followed by a valid identifier, and their values must be JSON literals of any type (take care to quote strings). Because they are JSON literals, they can only contain values, not arbitrary GROQ expressions, and are safe to pass from user input. If you pass an unquoted string, such as $type=myType, the HTTP API returns a 400 error: Unable to parse value of "$type=myType". Please quote string values.

For example, the following query may be given parameters such as $type="myType" and $object={"title": "myTitle", "value": 3}:

*[ _type == $type && title == $object.title && value > $object.value ]

In the HTTP API, pass each parameter as a URL query parameter with a JSON-encoded value, such as $type="myType". In a POST request, you can instead send parameters in the params object of the request body, without the $ prefix. For details, see the Query API reference.

Predefined parameters

Gotcha

The following parameters are predefined and available for use in all GROQ queries:

  • $identity (string): The ID of the current user, or <anonymous> for unauthenticated users.
  • $now (datetime): The current server time (UTC).

Was this page helpful?