How to use the HTTP JSON API
- hendrehaymanOP 2
I’ve downloaded the IOU contract from Parties and Authority — Daml SDK 2.7.6 documentation and launched the
daml sandboxin one terminal, plusdaml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --allow-insecure-tokensin another. But I can’t seem to get any response. I’ve triedcurl -X GET "http://127.0.0.1:7575/livez", but get no response.curl -X GET “http://127.0.0.1:7575/readyz”
[+] ledger ok
readyz check passedAnd
curl -H “application/json” -X POST “http://127.0.0.1:7575/v1/create” -d ‘{“templateId”: “Iou:Iou”,“payload”: {“issuer”: “Alice”,“owner”: “Alice”,“currency”: “USD”,“amount”: “999.99”,“observers”: } }’
{“errors”:[“missing Authorization header with OAuth 2.0 Bearer Token”],“status”:401}Any help on what I’m doing wrong?
- cocreature 2
Hi @hendrehayman, welcome to the forum!
The
/livezendpoint always returns an empty response. The only relevant information here is the 200 status code to indicate that the server is live. This is intended to be used as something like k8s liveness probe whereas/readyzcan be used for the readyness probe.As for the second error when making a query, for the JSON API you always need to supply a JWT even if the underlying ledger runs without authorization. The JSON API does not validate the JWT but it infers the party and other fields from the token. You can find more information on this in our documentation.
Using the example token in the documentation, a request to query all active contracts could look as follows:
curl localhost:7575/v1/query -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJNeUxlZGdlciIsImFwcGxpY2F0aW9uSWQiOiJmb29iYXIiLCJhY3RBcyI6WyJBbGljZSJdfX0.atGiYNc9HfBFbm8s9j5vvMv2sJUlVprFiRmLeoUpJeY" - hendrehayman 1
Thank you so much. I’ll try this now.