user2350063
user2350063

Reputation: 11

Neo4j REST API - create unique node

I am trying to use the REST API to create a unique node. However, I am getting the error about requiring the key 'uri' (see below). Based on the documented examples, this call creates and indexes the newly created node ... so there should not be a 'uri' paramater. My request and response are below. What am I doing wrong?

REQUEST:

http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create

{
    "key": "name",
    "value": "HOST",
    "properties": {
        "type": "company",
        "name": "HOST",
        "sequence": 1
    }
}

RESPONSE:

state:400, body:

{
  "message" : "Missing required key: \"uri\"",
  "exception" : "BadInputException",
  "fullname" : "org.neo4j.server.rest.repr.BadInputException",
  "stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
  "cause" : {
    "message" : "Missing required key: \"uri\"",
    "exception" : "BadInputException",
    "stacktrace" : [ "org.neo4j.server.rest.repr.DefaultFormat.validateKeys(DefaultFormat.java:153)", "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:88)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
    "fullname" : "org.neo4j.server.rest.repr.BadInputException"
  }
}

Using curl c:\apps\curl\curl-7.28.1-win64-nossl>curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"key":"name","value":"HOST","propert ies":{"type":"company","name":"HOST","sequence":1}}' http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create HTTP/1.1 400 Bad Request Content-Length: 489 Content-Encoding: UTF-8 Content-Type: application/json Access-Control-Allow-Origin: * Server: Jetty(6.1.25)

{ "message" : "Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.Str ingReader@1e70f68; line: 1, column: 2]", "exception" : "BadInputException", "stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(R estfulGraphDatabase.java:776)", "java.lang.reflect.Method.invoke(Unknown Source)" ] }

Upvotes: 1

Views: 1716

Answers (1)

RaduK
RaduK

Reputation: 1463

According to the doc, in 1.8 the url ends with '?unique' whereas in 1.9 is '?uniqueness=get_or_create'

I think this may cause your error.

see for 1.8: http://docs.neo4j.org/chunked/stable/rest-api-unique-indexes.html#rest-api-add-a-node-to-an-index-unless-a-node-already-exists-for-the-given-mapping

and 1.9: http://docs.neo4j.org/chunked/milestone/rest-api-unique-indexes.html

Upvotes: 0

Related Questions