0

I have a complexe request that perfectly works in Neo4j Browser that I want to use through API Rest, but there are Clauses I can't cope with.

The syntax looks like :

MATCH p=()-[*]->(node1)

WHERE …

WITH...

....

FOREACH … SET …

I constructed the query with Transactional Cyper as i have been suggested by @cybersam, but I don't manage to use more than one clause anyway.

To give an exemle, if I write the statement in one line :

    :POST /db/data/transaction/commit {

    "statements": [
    {
       "statement": "MATCH p = (m)-[*]->(n:SOL {PRB : {PRB1}}) WHERE nodes (p) 
MATCH q= (o:SOL {PRB : {PRB2}} RETURN n, p, o, q;",

 "parameters": {"PRB1": "Title of problem1", "PRB2": "Title of problem2"}
    }   ],   

"resultDataContents": ["graph"] }

I shall obtain :

{"results":[],"errors":[{"code":"Neo.ClientError.Statement.SyntaxError","message":"Invalid input 'R': expected whitespace, comment, ')' or a relationship pattern (line 1, column 90 (offset: 89))\r\n\"MATCH p = (m)-[*]->(n:SOL {PRB : {PRB1}}) WHERE nodes (p) MATCH q= (o:SOL {PRB : {PRB2}} RETURN n, p, o, q;\"\r\n ^"}]}

But if I put it in several lines, :

 :POST /db/data/transaction/commit {

 "statements": [
    {
      "statement": "MATCH p = (m)-[*]->(n:SOL {PRB : {PRB1}})
 WHERE nodes (p) 
 MATCH q= (o:SOL {PRB : {PRB2}} 
 RETURN n, p, o, q;",

"parameters": {"PRB1": "Title of problem1", "PRB2": "Title of problem2"}
    }
  ],

  "resultDataContents": ["graph"]
}

it is said :

{"results":[],"errors":[{"code":"Neo.ClientError.Request.InvalidFormat","message":"Unable to deserialize request: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: HttpInputOverHTTP@41fa906c; line: 4, column: 79]"}]}

Please, I need your help !

Alex

1 Answer 1

1

Using the Transaction Cypher HTTP API, you could just pass the same Cypher statement to the API.

To quote from this section of the doc, here is an example of the simplest way to do that:

Begin and commit a transaction in one request If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction, execute statements, and commit with just a single HTTP request.

Example request

  • POST http://localhost:7474/db/data/transaction/commit
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json

    {
      "statements" : [ {
        "statement" : "CREATE (n) RETURN id(n)"
      } ]
    }
    

Example response

  • 200: OK
  • Content-Type: application/json

    {
      "results" : [ {
        "columns" : [ "id(n)" ],
        "data" : [ {
          "row" : [ 6 ],
          "meta" : [ null ]
        } ]
      } ],
      "errors" : [ ]
    }
    
Sign up to request clarification or add additional context in comments.

5 Comments

So should I divide each part of the request in a specific statement ? How the statements would be linked together and connected with datas analysed ?
You pass your entire statement (in your example you have just one, consisting of multiple clauses).
With Transactional Cypher, it does'nt work also when I use more than one Clause. Read Upgrade of this question above...
You need to fix your Cypher code. It has numerous syntax issues. A WHERE clause needs to evaluate to a boolean value. What is your WHERE clause trying to test? Also, you are missing a right parenthesis at the end of your second MATCH clause. Test your Cypher using the neo4j browser, or at console.neo4j.org before you use it with the API. Finally, you should avoid trying to do 2 unrelated queries in the same statement, as that will cause a cartesian product.
Your advices helped me to find out the problem I encountered. Thanks a lot !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.