Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Can we add query capability to fetchByKey from the JSON API?Forum ↗

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

App Development3 posts190 views7 likesLast activity Jan 2022
LE
Leonid_RozenbergOP
Jan 2022

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?

CO
cocreature
Jan 2022

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
  with
    p : Party
    i : Int
    t : Text
  where
    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).

LE
Leonid_Rozenberg
Jan 2022

Thank you

← Back to Discussions