Registry API examples ********************* This document contains examples on how to use the :doc:`Registry Utility API <../../registry-user-guide/index>` in practice. It is not intended to be an extensive guide, but rather a starting point for developers to get familiar with the API. Prerequisites ============= #. A running validator node connected to one of DevNet, TestNet, or MainNet #. The Utility DARs installed on your validator node #. A valid business user token (````) obtained from the IAM of the validator node #. A business user and associated party (````) created through the Validator API #. The JSON API endpoint (````) of the participant node #. ``curl`` and ``jq`` installed on your system Set environment variables ------------------------- .. code-block:: shell export HTTP_JSON_API= export USER_TOKEN= cURL Examples ============= **Note:** The JSON API in Canton 3 does **not** have query support as it did in `Canton 2`_. Because of this, filtering must be done on the client side. Instead, it is recommended to use the `PQS`_ for such scenarios. Query all assets a registrar has in custody ------------------------------------------- The example below retrieves all :doc:`Holdings <../../registry-holding-model/Utility-Registry-Holding-V0-Holding>` for a specific registrar. Set the ``REGISTRAR`` environment variables to the registrar you want to query assets for. We assume that the token you configured has ``readAs`` rights for this party. .. code-block:: shell ( curl \ --url "${HTTP_JSON_API}/v1/query" \ --header "Authorization: Bearer ${USER_TOKEN}" \ --header "Content-Type: application/json" \ --request POST \ --data @- <` for details. For the following example you should get **two** user tokens, one for the holder and one for the registrar. Set the ``PACKAGE_ID`` to the utility-registry-app-v0-0.1.0 id from :doc:`../../dar-versions`, the ``HOLDER_SERVICE_CID`` to the contract id of the holder service, and the ``REGISTRAR`` to the registrar party id. The following example exercises the ``HolderService_RequestMint`` choice of the ``HolderService`` contract, and in case of success, returns the ``mintRequestCid``. .. code-block:: shell ( curl \ --url "${HTTP_JSON_API}/v1/exercise" \ --header "Authorization: Bearer ${HOLDER_USER_TOKEN}" \ --header "Content-Type: application/json" \ --request POST \ --data @- <", "choice": "HolderService_RequestMint", "argument": { "registrar": "${REGISTRAR}", "instrumentIdentifier": { "source": "", "id": "", "scheme": "" }, "amount": 100, "reference": "", "batch": { "id": "", "size": 1, "settlementFrom": "", "settlementUntil": "" }, "holdingLabel": "", "size": 1, "settlementFrom": "", "settlementUntil": "" } } } EOF ) | jq ' if has("errors") then . else .result.exerciseResult.transferRequestCid end ' If the request was successful, use the returned ``transferRequestCid`` for the ``cid`` in argument in the following example. Pay attention to the authorization token, it should be the token of the receiver. .. code-block:: shell ( curl \ --url "${HTTP_JSON_API}/v1/exercise" \ --header "Authorization: Bearer ${RECEIVER_USER_TOKEN}" \ --header "Content-Type: application/json" \ --request POST \ --data @- <", "choice": "HolderService_AcceptTransferOffer", "argument": { "cid": "", "payload": { "receiverLabel": "