Skip to content
CCPEDIAby Unity Nodes
App Development

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

3 posts213 views7 likesLast activity Jan 2022

  1. Leonid_RozenbergOP 1

    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?

  2. cocreature 4

    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).

  3. Leonid_Rozenberg 2

    Thank you