Neo4j Python REST API

170 Views Asked by At

Query via Python REST-APi enter image description here message: Invalid input: ':' enter image description here

Hello, i am starting a query via my Python-Neo4j-Api. But the code ist not working, resulting in the the error message above. But the same query is working in the Neo4J Desktop App. Why is it working in the Neo4j Desktop App, but not via my Api Query. Why is the : before param a Problem?

I am new to Python and Neo4j, please help. King regards.

Trying to query via a Python-Neo4j-RestAPI.

2

There are 2 best solutions below

1
On BEST ANSWER

Below is the syntax on passing parameters in neo4j python driver. Unfortunately, you cannot use labels or relationship types in the parameter. If you need to pass labels (like Human:Moviestar) then you can use string function in python like this: passing parameters in neo4j using python

name = "Tom Cruise"
placeOfBirth = "Syracuse, New York, United States" 
query = "Create (n:Human:Moviestar { name: $name, placeOfBirth: $placeOfBirth})"
session = driver.session()
result = session.run(query, name=name, placeOfBirth=placeOfBirth) 
0
On

I see that you have been working with the database though the browser application. So commands that are prefixed with ":" like :params or :connect are browser commands and is not valid cypher. Instead, in python pass your parameters as the second argument to your to your session.run() function or transaction. Then use variable substitution to in your cypher query.

params = {"name": "Tom Hanks" }
with driver.session as session:
    result = session.run ("MATCH (p:person) where p.name = $name return p", params)