Neo4j Connection Problem: API Error
Mtmmmmm opened this issue · 2 comments
I can build up the connection between Neo4j and R. However, I got an error message when I call the API. Below is an example of the error when I tried to run a Cypher query pulling data.
> library(neo4r)
> library(magrittr)
> con <- neo4j_api$new(url = "http://localhost:7474",
+ user = "xxx", password = "xxx")
>
> con$ping()
[1] 401
>
> 'MATCH (p:Person) -[r:ACTED_IN] -> (m:Movie) RETURN *;' %>%
+ call_neo4j(con, output = "json")
Error: API error
Thanks in advance.
Hey,
It seems that the API returns an error when you ping it (https://neo4j.com/docs/http-api/current/http-api/security/#http-api-missing-authorization)
Are you sure you're providing the right auth elements?
Hi Colin,
Thanks for your quickly reply. I confirmed that the error was due to the wrong auth, sorry for the confusion.
As I am new to neo4j, I have 2 questions would like to ask:
- Now I have the connection built up, however, I still have error messages when querying data from Neo4j API. I am using Movie dataset in Neo4j and below is the code and error.
> res1 <- 'MATCH (p:Person) -[r:ACTED_IN] -> (m:Movie) RETURN p.name, m.title;' %>%
+ call_neo4j(con)
Error in names(object) <- nm :
'names' attribute [2] must be the same length as the vector [1]
>
> res2 <- 'MATCH (p:Person) -[r:ACTED_IN] -> (m:Movie) RETURN *;' %>%
+ call_neo4j(con)
Error in cbind_all(x) : Argument 6 must be length 1, not 3
>
> res3 <- 'MATCH (p:Person) -[r:ACTED_IN] -> (m:Movie) WHERE p.name = "Tom Hanks" RETURN *;' %>%
+ call_neo4j(con)
Error in cbind_all(x) : Argument 6 must be length 1, not 6
As above, I tried to extract data in 3 different ways that I will be using for my ongoing project, they all have error messages. I assume that is because different types of nodes have different number of records (eg. 1 movie can contain multiple actors, this leads the error in res1)
The only way worked for me was to specify type = "graph"
when calling the API.
- I know we can create new elements in Neo4j by sending cypher query back using PASTE/SEND_ CYPHER, I am a bit stuck on the syntax by following the examples in neo4r document. I am wondering how can I create new nodes and merge them with existing nodes by creating new relationships in R. Ideally, I would like to create those new elements by specifying constraints, labels and properties in R statement and have them automatically writing back to Neo4j database.
Thank you so much!