Skip to content
Discussions/App Development/Postman error against the HTTP JSON APIForum ↗

Postman error against the HTTP JSON API

App Development15 posts4,083 views4 likesLast activity Feb 2023
GY
gyorgybalazsiOP
Aug 2022

I’m trying to query the HTTP JSON API with Postman, but get the following answer. On some forums they say it’s an error on the server side. Is that true, or I am doing something wrong?

GET http://localhost:7575/v1/query: {
  "Error": "Parse Error: Expected HTTP/",
  "Request Headers": {
    "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJzYW5kYm94IiwiYXBwbGljYXRpb25JZCI6ImZvb2JhciIsImFjdEFzIjpbImNhcnJpZXIiXX19.E6TKljEjPA-1QxH-oR0k0GSuzbz6IaGrwExvuryUajA",
    "content-type": "application/json",
    "user-agent": "PostmanRuntime/7.29.0",
    "accept": "*/*",
    "postman-token": "253888c3-6822-4915-b96f-c219dc5b7b1d",
    "host": "localhost:7575",
    "accept-encoding": "gzip, deflate, br",
    "connection": "keep-alive"
  },
  "Request Body": "{}"
}
GA
Gary_Verhaegen
Aug 2022

I’m not familiar with Postman; is there some sort of debug mode/output that would show you (and us if you share it) the exact content of the HTTP request it sent?

CO
cocreature
Aug 2022

The JSON API logs would also be very useful.

GY
gyorgybalazsi
Aug 2022

I can copy to clipboard what I included in the question.

This is printed to the console:

GET http://localhost:7575/v1/query
Error: Parse Error: Expected HTTP/
Proxy
id: "822b89ae-343f-4b35-8f46-be6bf32361ff"
disabled: false
host: "127.0.0.1."
match: {…}
pattern: "http://*:*/*"
port: 6865
tunnel: false
authenticate: false
Request Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJzYW5kYm94IiwiYXBwbGljYXRpb25JZCI6ImZvb2JhciIsImFjdEFzIjpbImNhcnJpZXIiXX19.E6TKljEjPA-1QxH-oR0k0GSuzbz6IaGrwExvuryUajA
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: 253888c3-6822-4915-b96f-c219dc5b7b1d
Host: localhost:7575
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Request Body
{}
GY
gyorgybalazsi
Aug 2022

I cannot see any effect of the Potman request in the log:

gyorgybalazsi@BGY init_examples % sh start_json_api.sh
08-08-2022 11:52:34.870 [main] INFO  com.daml.http.Main - Config(ledgerHost=localhost, ledgerPort=6865, address=localhost, httpPort=7575, portFile=None, packageReloadInterval=5 seconds, packageMaxInboundMessageSize=None, maxInboundMessageSize=4194304, tlsConfig=TlsConfiguration(false,None,None,None,None,REQUIRE,false,None), jdbcConfig=None, staticContentConfig=None, allowNonHttps=false, wsConfig=None, nonRepudiationCertificateFile=None, nonRepudiationPrivateKeyFile=None, nonRepudiationPrivateKeyAlgorithm=None, surrogateTpIdCacheMaxEntries=None), context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:35.352 [http-json-ledger-api-akka.actor.default-dispatcher-5] INFO  akka.event.slf4j.Slf4jLogger - Slf4jLogger started 
08-08-2022 11:52:35.724 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.HttpService - HTTP Server pre-startup, context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:36.066 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.LedgerClient - Attempting to connect to the ledger localhost:6865 (600 attempts), context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:36.778 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.LedgerClient - Attempt 1/600 succeeded!, context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:36.783 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.LedgerClient - Attempting to connect to the ledger localhost:6865 (600 attempts), context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:36.792 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.LedgerClient - Attempt 1/600 succeeded!, context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:36.793 [http-json-ledger-api-akka.actor.default-dispatcher-9] INFO  com.daml.http.HttpService - contractDao: None, context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
08-08-2022 11:52:37.663 [http-json-ledger-api-akka.actor.default-dispatcher-11] INFO  com.daml.http.Main - Started server: (ServerBinding(/127.0.0.1:7575),None), context: {instance_uuid: "8d74cdb2-770a-4df7-956f-2946a10bdc90"} 
CO
cocreature
Aug 2022

What happens if you send the same request via Curl, e.g., curl localhost:7575/v1/query?

GY
gyorgybalazsi
Aug 2022
cocreature:

curl localhost:7575/v1/query?

I get a correct answer:

% curl --location --request GET 'http://localhost:7575/v1/query' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJzYW5kYm94IiwiYXBwbGljYXRpb25JZCI6ImZvb2JhciIsImFjdEFzIjpbImNhcnJpZXIiXX19.E6TKljEjPA-1QxH-oR0k0GSuzbz6IaGrwExvuryUajA' \
--header 'Content-Type: application/json' \
--data-raw '{}'
{"result":[],"status":200}% 
CO
cocreature
Aug 2022

Sounds like it’s a postman issue.

GY
gyorgybalazsi
Aug 2022

May be. Some time ago I used Postman for this purpose.

ST
stefanobaghino-da
Aug 2022

Looks like the HTTP version is missing from the HTTP request line sent by Postman (RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1). The request line should be something like

GET http://localhost:7575/v1/query HTTP/1.1

Postman is such a mature tool I’m a bit surprised by the error, there’s probably something we’re overlooking.

GA
Gary_Verhaegen
Aug 2022

Can you try that curl command again with an added -v at the end, and report the full result?

GY
gyorgybalazsi
Aug 2022

That’s it:

% curl --location --request GET 'http://localhost:7575/v1/query' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJzYW5kYm94IiwiYXBwbGljYXRpb25JZCI6ImZvb2JhciIsImFjdEFzIjpbImNhcnJpZXIiXX19.E6TKljEjPA-1QxH-oR0k0GSuzbz6IaGrwExvuryUajA' \
--header 'Content-Type: application/json' \
--data-raw '{}' -v
*   Trying 127.0.0.1:7575...
* Connected to localhost (127.0.0.1) port 7575 (#0)
> GET /v1/query HTTP/1.1
> Host: localhost:7575
> User-Agent: curl/7.79.1
> Accept: */*
> Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJzYW5kYm94IiwiYXBwbGljYXRpb25JZCI6ImZvb2JhciIsImFjdEFzIjpbImNhcnJpZXIiXX19.E6TKljEjPA-1QxH-oR0k0GSuzbz6IaGrwExvuryUajA
> Content-Type: application/json
> Content-Length: 2
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: akka-http/10.2.8
< Date: Mon, 08 Aug 2022 13:55:37 GMT
< Transfer-Encoding: chunked
< Content-Type: application/json
< 
* Connection #0 to host localhost left intact
{"result":[],"status":200}% 
GA
Gary_Verhaegen
Aug 2022

I wanted to double-check that it wasn’t an issue with the response, but it looks well-formed to me.

I don’t know how to help further in the absence of an option for Postman to display detailed logs like these, i.e. that include the exact HTTP message sent.

GY
gyorgybalazsi
Aug 2022

Thank you for your effort, I let this go, I can solve my problem with different tools.

WA
WallaceKelly
Feb 2023

I ran into this problem just now. I’d like to document the solution that worked for me, in case someone finds this page like I did. In my case…


I had my Postman port number variable set to the wrong port. In my Postman request, I was using {{ApiPort}}, which I had previously configured for the Ledger API, port 6865. When I blindly reused my {{ApiPort}} variable for a new JSON API request, I received the message:

GET http://localhost:6865/v1/query
Error: Parse Error: Expected HTTP/

When I changed the value of {{ApiPort}} to 7575, the GET of the v1/query endpoint returned a proper result and I no longer saw the error message.


This does not appear to have been the case for gyorgybalazsi, but if you make the same mistake I did,… you are welcome! :slight_smile:

← Back to Discussions