I want to use REST API (.NET) and to issue a merge query to execute for neo4j database. My query is:
{ "query" : "MERGE (n:Person { props } ) ON CREATE SET n.id = 55 RETURN n" , "params" :{ "props" : { "name" : 'Mahsa', "lastname" : 'Hassankashi' } }}
OR
{ "query" : "MERGE (n:Person { props } ) ON CREATE SET n.id = {PersonID} RETURN n" , "params" :{ "props" : { "name" : 'Mahsa' } , "PersonID" : 55} }
But my "HttpWebResponse response" is null and when HttpWebResponse returns null because when I send it to stream it at this line:
Stream requestStream = request.GetRequestStream();
It has Length and position error:
(1): 'requestStream.Position' threw an exception of type 'System.NotSupportedException'
(2). "This stream does not support seek operations.", it means my query is not proper. How can I correct query.
It is important that I have answer from my httpwebresponse for other cypher query, it means that my sending request(cypher) and receiving response is possible by other queries.
Below Query works when I put it directly on neo4j 2.2.4:
MERGE (n:Person { name : "mahsa", lastname : "hassankashi" } ) ON CREATE SET n.id=55 RETURN n
Request Class:
//****** Send Cypher Query by HttpWebRequest and Stream
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url);
request.KeepAlive = true;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = methodType;
request.Timeout = Timeout.Infinite;
byte[] postBytes = Encoding.UTF8.GetBytes(json);
request.ContentType = "application/json; charset=UTF-8";
request.Accept = "application/json";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
response = (HttpWebResponse)request.GetResponse();
Thank you in advanced for help.
Personlabel? - cybersamMERGEyou have to send individual parameters (values) for each property, something likeMERGE (n:Person {name: {name}, lastname: {lastname}})and"params":{"name":"mahsa","lastname":"hassankashi"}. Or unpack the single parameter map in the query. - jjaderberg