Http api query returning 400

I’m passing this query as a json body in accordance with
https://v1-docs.xtdb.com/clients/http/openapi/1.24.3/#/paths/~1_xtdb~1query/post

{
  "query": {
    "find": ["e"],
    "where": [["e", "xt/id", "_"]],
    "limit": 100
  },
  "in-args": ["08k4Z2rD3uuwkvWrd8HHe"]
}

Can’t figure out why I’m receiving a 400.

Raw HTTP request:

– Client >>> Server

POST /_xtdb/query HTTP/1.1\x0d
Accept: application/json\x0d
Content-Type: application/transit+json\x0d
Accept-Encoding: gzip\x0d
Content-Length: 100\x0d
Host: localhost:8999\x0d
Connection: close\x0d
\x0d
{"query":{"find":["e"],"where":[["e","xt/id","_"]],"limit":100},"in-args" ["08k4Z2rD3uuwkvWrd8HHe"]}

– Client <<< Server

HTTP/1.1 400 Bad Request\x0d
Connection: close\x0d
Content-Type: application/json;charset=utf-8\x0d
Content-Length: 999\x0d
Server: Jetty(9.4.43.v20210629)\x0d
\x0d
{"spec":"(juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:xtdb.http-server.query/query] :opt-un
 [:xtdb.http-server.query/in-args]), :type :map, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/key->spec {:in-args
:xtdb.http-server.query/in-args, :query :xtdb.http-server.query/query}, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys #{:in-args
:query}, :juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys-req #{:query},
:juxt.clojars-mirrors.spec-tools.v0v10v5.spec-tools.parse/keys-opt #{:in-args}, :leaf? false})","problems":[{"path":[],"pred":"(clojure.core/fn [%]
(clojure.core/contains? % :query))","val":{},"via":["xtdb.http-server.query/body-params"],"in":[]}],"type":"juxt.clojars-mirrors.reitit-core.v0v5v15.r
eitit.coercion/request-coercion","coercion":"spec","value":{"query":{"find":["e"],"where":[["e","xt/id","_"]],"limit":100},"in-args":["08k4Z2rD3uuwkvW
rd8HHe"]},"in":["request","body-params"]}

Hey @tempire

The application/transit+json transport is really only intended for programmatic usage via a transit library (i.e. using it as if it were a regular JSON endpoint is not supported). Although I’m not sure why you’re seeing this particular error :thinking:

Does the application/edn route work for you instead? e.g.

curl --request POST \
  --url 'http://localhost:3000/_xtdb/query?=' \
  --header 'Content-Type: application/edn' \
  --data '{:query
 {:find [?e]
        :where [[?e :xt/id _]]}}'

Alternatively you could try using a transit client library for your chosen language.

That does work, yes.

I’m not familiar with transit+json at all; what I’m really interested in is sending queries using json with variable substitution - as opposed to constructing an edn string.

Is this supported?

v1 Datalog queries are specified using edn and there’s not really a way around that. There are many libraries that exist which could help, e.g. looking at JS you can work with edn, with transit, or with Datalog options …and similarly you will find other libs across many other languages, but there’s nothing we can officially support you with today (although I’d be happy to discuss tradeoffs and help you navigate)

Which language(s) are you working with?