You have to specify a query parameter when trying to curl Neo4j

I am getting this error message:

You have to provide the 'query' parameter ...

      

when i try to use Neo4j

rest api. I do this via curl

:

$ curl 'http://neo4j:root@127.0.0.1:7474/db/data/cypher' -d '
  {
     "query": "START n=node(*) RETURN distinct labels(n)", "params":{}
  }'

      

If, however, I run the same query programmatically using the same library in Python

, then that's ok - I get some results back. So what else do I have to point out to get my team to curl

work?

+3


source to share


1 answer


The Neo server expects a content type application/json

that can be specified by default in your client, but not in cURL. Specifying the content type directly with a parameter -H

in cURL should work, something like

$ curl -X POST -H 'Content-type: application/json' \    
  'http://neo4j:root@127.0.0.1:7474/db/data/cypher' -d '
  {
     "query": "START n=node(*) RETURN distinct labels(n)", "params":{}
  }'

      

On my machine:



[~/apps/neo]$ curl -X POST -H 'Content-type: application/json'     'http://neo4j:root@127.0.0.1:7474/db/data/cypher' -d '
  {
     "query": "START n=node(*) RETURN distinct labels(n)", "params":{}
  }'
{
  "columns" : [ "labels(n)" ],
  "data" : [ [ [ "Movie" ] ], [ [ "Person" ] ], [ [ "PublicDomain" ] ] ]
}

      

Without the content type header, I see the same error.

Interestingly, as you noted in the comments, you can invoke this request without an option -X POST

in cURL. This works due to the presence of a parameter -d

that forces the POST method.

+3


source







All Articles