Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Use wscat with HTTP JSON API Streaming API?Forum ↗

Use wscat with HTTP JSON API Streaming API?

App Development3 posts112 views1 likesLast activity Aug 2026
WA
WallaceKellyOP
Jan 2025

Is it possible to use wscat with the 2.x HTTP JSON API?

  1. Start the HTTP JSON API.

    daml new test
    
    cd test
    
    daml start
    
  2. Confirm the contracts exist and the token is good with curl and v1/query.
    (the token should work for you too)

    curl http://localhost:7575/v1/query --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2RhbWwuY29tL2p3dC9hdWQvcGFydGljaXBhbnQvc2FuZGJveCIsInN1YiI6ImFsaWNlIiwiaXNzIjoiaWdub3JlZCJ9.uKjafJLbf4KCBL6ys1pBT2jxs0DpflUpKX-5ZRtLVs'
    
  3. Stream the contracts with v1/stream/query.

    How to do this with wscat?

WA
WallaceKelly
Jan 2025

This works:

wscat --connect http://localhost:7575/v1/stream/query \
      --subprotocol 'daml.ws.auth' \
      --subprotocol 'jwt.token.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2RhbWwuY29tL2p3dC9hdWQvcGFydGljaXBhbnQvc2FuZGJveCIsInN1YiI6ImFsaWNlIiwiaXNzIjoiaWdub3JlZCJ9.uKjafJLbf4KCgBL6ys1pBT2jxs0DpflUpKX-5ZRtLVs' \
      --execute '{ "templateIds" : [ "bc6d87a0d45cb8e2a9ea194ab9d380e79ab9622695c8fa9ab6c23d764d1e0df5:Main:Asset" ] }'
Results
{
  "events": [
    {
      "created": {
        "agreementText": "",
        "contractId": "003b0bf878e6602afdeae71c1f8abb032d27ed83b0a6e8e6b59aa351cd705ed82dca03122087e0aa95e3e93725fe43fe942d4c5c5ace112c6bcfd95b90581f1004bd47fab2",
        "observers": [],
        "payload": {
          "issuer": "Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd",
          "owner": "Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd",
          "name": "TV"
        },
        "signatories": [
          "Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd"
        ],
        "templateId": "bc6d87a0d45cb8e2a9ea194ab9d380e79ab9622695c8fa9ab6c23d764d1e0df5:Main:Asset"
      },
      "matchedQueries": [
        0
      ]
    }
  ]
}
{
  "events": [],
  "offset": "000000000000000009"
}

Alternatively, connect and then submit the filter:

wscat --connect http://localhost:7575/v1/stream/query \
      --subprotocol 'daml.ws.auth' \
      --subprotocol 'jwt.token.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2RhbWwuY29tL2p3dC9hdWQvcGFydGljaXBhbnQvc2FuZGJveCIsInN1YiI6ImFsaWNlIiwiaXNzIjoiaWdub3JlZCJ9.uKjafJLbf4KCgBL6ys1pBT2jxs0DpflUpKX-5ZRtLVs'

{ "templateIds" : [ "bc6d87a0d45cb8e2a9ea194ab9d380e79ab9622695c8fa9ab6c23d764d1e0df5:Main:Asset" ] }
Results
< {"events":[{"created":{"agreementText":"","contractId":"003b0bf878e6602afdeae71c1f8abb032d27ed83b0a6e8e6b59aa351cd705ed82dca03122087e0aa95e3e93725fe43fe942d4c5c5ace112c6bcfd95b90581f1004bd47fab2","observers":[],"payload":{"issuer":"Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd","owner":"Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd","name":"TV"},"signatories":["Alice::1220f3de2718124a544a3d46f3ef32fb51ffc963ba761bbadaed8b4667d482436fbd"],"templateId":"bc6d87a0d45cb8e2a9ea194ab9d380e79ab9622695c8fa9ab6c23d764d1e0df5:Main:Asset"},"matchedQueries":[0]}]}
< {"events":[],"offset":"000000000000000009"}
< {"events":[],"offset":"000000000000000009"}
            :
            :
WA
WallaceKelly
Aug 2026 1

I find that the JWT can alternatively be sent as an Authorization: Bearer header. This is better than being sent as a subprotocol jwt.token.<place token here> in a Sec-WebSocket-Protocol header. It is better because network components and tooling often avoid exposing Authorization: Bearer header contents.

wscat --connect ws://localhost:8000/api/json-api/v2/state/active-contracts \
      -H 'Authorization: Bearer eyJhbGciOiJ...' \
      --subprotocol 'daml.ws.auth' \
      --execute '{"activeAtOffset":1764,"verbose":false,"eventFormat":{"filtersByParty":...'
← Back to Discussions