Disagreeing with @hydraruiz, I guess you're running a Neo4j 2.2.0-M0x version. This one has authentication enabled by default. You first need to acquire a token by providing your username and password.
curl -H "Content-Type: application/json" -d '{"username":"neo4j", "password":"mypassword"}' http://localhost:7474/authentication
{
"username" : "neo4j",
"password_change" : "http://localhost:7474/user/neo4j/password",
"password_change_required" : false,
"authorization_token" : "53eaa48a972439012868a8d5463e0c3d",
"authorization_token_change" : "http://localhost:7474/user/neo4j/authorization_token"
}
Subsequent calls to the REST API use the token in the Authorization header. According to the docs the value of the http Authorization header is Basic realm="Neo4j"
plus the base64 encoded token prefixed by a colon. We can use command line tools for this: echo -n ":tokenstring" | base64
. For simplicity I emit a trivial cypher statement match (n) return count(n)
:
curl -H "Authorization: Basic realm=\"Neo4j\" `echo -n ":53eaa48a972439012868a8d5463e0c3d" | base64`" \
-H "Content-Type: application/json" \
-d '{"statements":[{"statement":"match (n) return count(n)"}]}' \
http://localhost:7474/db/data/transaction/commit
returns:
{"results":[{"columns":["count(n)"],"data":[{"row":[0]}]}],"errors":[]}
That means the authentication worked.