Can Postman be used to interact with the ledger (gRPC) API?
- gyorgybalazsiOP 1
Previously, there were reports about a Postman bug which prevented Postman from being used to interact with the ledger (gRPC) API, via server reflection.
Then there were reports about the bug having been fixed.
Now as I try to use Postman (Version 10.24.7) against the ledger API, I can see the following:
- Server reflection seems to work fine, in as much as the dropdown menu contains the list of the API services.
- Getting the ledger id works fine.
- While trying to get the active contracts for a party, I get an “invalid argument” error, although the equivalent gRPCurl command works fine.
The service chosen in the dropdown menu in Postman:
ActiveContractsService/GetActiveContractsMessage body:
{ "ledgerId": "bvzgeb91p8gq6cms", "filter": { "filtersByParty": [ { "key":"ledger-party-85c0386e-f014-4a0c-80f3-58c7e1ea361b::1220a8af397e1f38697d7109d5e999e71cd341b1b71cf5cb88100e9a7cbc0660b971" } ] } }JWT is valid.
The answer:
INVALID_ARGUMENT(8,d54ddcc4): The submitted command has invalid arguments: filtersByParty cannot be emptyThe equivalent gRPCurl command (copied from the Daml Hub docs) works fine:
TOKEN="XXX" LEDGER_ID=bvzgeb91p8gq6cms LEDGER_DOMAIN=bvzgeb91p8gq6cms.daml.app DAML_LEDGER_PARTY=ledger-party-85c0386e-f014-4a0c-80f3-58c7e1ea361b::1220a8af397e1f38697d7109d5e999e71cd341b1b71cf5cb88100e9a7cbc0660b971 grpcurl -H "Authorization: Bearer $TOKEN" \ -d "{\"ledgerId\":\"${LEDGER_ID}\", \"filter\":{\"filtersByParty\":[{\"key\": \"${DAML_LEDGER_PARTY}\"}]}}" \ "${LEDGER_DOMAIN}:443" com.daml.ledger.api.v1.ActiveContractsService/GetActiveContractsIs there still a bug in Postman, god forbid in Canton, or I am doing something wrong?
- sormeter 2
Likely a bug in Postman. Generally grpcurl is the way to go when interacting with the gRPC services, as it is built for that. Postman was tailored to http restful-apis, and only added gRPC support later, and the gRPC support is likely to lag in that product.
Another useful one for browsing the grpc interfaces is grpcui — the command line interface to this is very similar to grpcurl, but it gives you a browser based interface to see the various groc services and required payload for each GitHub - fullstorydev/grpcui: An interactive web UI for gRPC, along the lines of postman
- gyorgybalazsi
Thank you!
- Ianw1 1
FWIW this query works for me in Postman:
{ "filter": {"filters_by_party": {"Alice::1220887aa5ccf52d4f40bce8c132db99fa87c63b2f0bf0809b63592b5aa8e3ccb3e8":{"inclusive":{"template_ids": [{"package_id" : "d3a8a18f73f71026ca42ccefcc466e01cee6706a0408d01c96c6af84a6dfd817","module_name": "Main", "entity_name": "Asset"}]}}}}, "ledger_id": "sandbox", "verbose": true }Albeit using Sandbox.
- sormeter 1
Ah yes looks like Postman does support gRPC now
Likely need to add the use token as a bearer header to get this to work for an auth’d remote ledger then
Background This page documents how to setup Postman to explore the Ledger API. You may already be familiar with using Postman to query JSON API endpoints. In 2022, Postman added support for gRPC endpoints. The Ledger API is a collection of gRPC endpoints. You might consider additionally Using gRPC UI to Explore the Ledger API. Both Postman and gRPC UI have their advantages. These notes are based on: macOS Daml SDK 2.4 Postman Version 10.6.7 (updated Dec 14, 2022) API Setup Start the San…
- mgodf89
To provide anyone else who sees this with options:
- I have used grpcui effectively (was able to pull a health dump, query ledger, etc.)
- Other DA colleagues have recommended wombat which also looks interesting
- gyorgybalazsi
Ianw1:{ "filter": {"filters_by_party": {"Alice::1220887aa5ccf52d4f40bce8c132db99fa87c63b2f0bf0809b63592b5aa8e3ccb3e8":{"inclusive":{"template_ids": [{"package_id" : "d3a8a18f73f71026ca42ccefcc466e01cee6706a0408d01c96c6af84a6dfd817","module_name": "Main", "entity_name": "Asset"}]}}}}, "ledger_id": "sandbox", "verbose": true }That didn’t work for me for some unknown reason, but the following worked, so thank you for the hint:
{ "filter": { "filters_by_party": [ { "key":"ledger-party-30a2c552-a904-4725-a841-1667ea9e4448::1220564ea370a7ef9650929f7cb780aac36416d0fcd1e22f4be0806ee5ca6a060724", "value": { "inclusive": { "template_ids": [ { "package_id": "d12686a437954ad403499d07662bc607752ce671cb2437805def29589cc894f6", "module_name": "Main", "entity_name": "Asset" } ] } } } ] }, "ledger_id": "dnafeidtzwihod5v", "verbose": true }Note to myself: RTFM, this is where I should’ve been looking: Ledger API Reference — Daml SDK 2.9.4 documentation.
- gyorgybalazsi
Yes, I added the token to Postman, there was a problem with the request body JSON, but now it works. Thank you for looking into this!
- WallaceKelly 2
- gyorgybalazsi
Yes, thanks, it works now. I just messed up the JSON structure.
