Can we add query capability to fetchByKey from the JSON API?

I noticed that the fetch-by-key endpoint does not support the query-lang because the intent to just fetch one key. Would it be possible to extend that end-point so that I can ask for all contracts based on a restricted set of keys?

1 Like

The advantage of the fetch by key endpoint is that they are more efficient than regular queries because we have specific indices for key equality.

There is no querying functionality for keys and it’s somewhat redundant: The key is always derived from the underlying contract payload. So (ignoring some potential restrictions in the JSON API querying language) you can translate a query on the key to a query on the contract payload.

As a simple example:
Consider this template

template T
    p : Party
    i : Int
    t : Text
    signatory p
    key (p, i)
    maintainer key._1

Instead of querying for everything with keys of the form (p, i > 5) you can also query for all contracts with i > 5 (and the respective party for p).


Thank you