Fetch contracts using contractId

Hello DAMLers,

I’d like to fetch contracts by contractId using the JSON API using the following:

POST http://localhost:7575/v1/query

{
    "templateIds": ["Main:Event"],
    "query": {"contractId": "00b21c2931bbfd9dccb1496f77646d941a8aec04eaea4d911dafad68d28eb5ba83ca001220a997d1a147706a2496b7a9263fbcf4c6a7104151dcc226f77cd5fa5159165995"}
}

I got:

{
    "errors": [
        "HTTP JSON API Server Error"
    ],
    "status": 500
}

The contractId is fetched using GraphQL API and I can’t retrieve contract payload using the same API because it’s nested in fields and types and not a simple contracts payload.

Do you have any suggestions?

The /v1/query endpoint only queries by payload. For fetching contracts by contract id you need to use /v1/fetch:

Note that the payload looks slightly different there. You want something like:

{
  "templateIds": ["Main:Asset"],
  "contractId": "0068feeab28d1e37de0ae65cda5315bf55e745f8a9c1b0e4a8d56f975f5f031cf6ca00122008724be78f5a2be635e6ab1bf58b7791ab7d5095b8bda43b896d0d3068c7a1c3"
}
1 Like

Solved the problem. Thank you so much.

1 Like

Please how do I make the fetch request correctly in React? In a sandbox, when I log in as a user who is observer of this contract

useStreamQueries(Model.Main.Provider.ReferralDetails)
 .contracts.filter(x => x.contractId === query.contractId)

actually works and the given contract is listed, but :

useFetch(Model.Main.Provider.ReferralDetails, query.contractId).contract

returns null even though navigator can list it. I’ve been stuck on that for whole day. What might be the reasons it returns null ?

@Jakub_Liska, could you please post your question on a new thread? New questions should always be posted on a new thread. This makes the threads navigable and readable, and the forum tidy and searchable.