Skip to content
Discussions/App Development/How to use the HTTP JSON APIForum ↗

How to use the HTTP JSON API

App Development3 posts538 views5 likesLast activity Mar 2021
HE
hendrehaymanOP
Mar 2021

I’ve downloaded the IOU contract from Parties and Authority — Daml SDK 2.7.6 documentation and launched the daml sandbox in one terminal, plus daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --allow-insecure-tokens in another. But I can’t seem to get any response. I’ve tried curl -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 passed

And

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?

CO
cocreature
Mar 2021

Hi @hendrehayman, welcome to the forum!

The /livez endpoint 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 /readyz can 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"
HE
hendrehayman
Mar 2021

Thank you so much. I’ll try this now.

← Back to Discussions