How to call Neo4j database api in R Studio

Viewed 126

Please I created a Neo4j database instance, and I am trying to call it in R Studio, using the neo4r and neo4jshell packages. After running the api call, I still get a 404even though I correctly specified the url, username, and password. Please find my code below:

library(neo4r)
library(neo4jshell)

myTwitter <- neo4j_api$new(
  
  url = "http://54.152.83.7:7474",
  user = "neo4j", 
  password = "mypassword"
)


myTwitter$ping()

When I run the last line of code, I get the 404 instead of 200, which obviously means my api call was not successful. Please I would appreciate your helpful suggestions. Thank you

1 Answers

HTTP endpoints were changed since version 4 of Neo4J

  • Neo4j v3 had endpoint http://localhost:7474/db/data
  • Neo4j v4 uses http://localhost:7474/db/{databaseName}/tx instead of it.

Seems like Neo4j library for R needs to be updated...

I'm not familiar with R but you could try to use available HTTP client for R that supports Basic authentication to send POST requests to Neo4J API with JSON payload. I also see you use http schema which means your credentials will be sent as plain text through the network, which is not good.

Payload for such requests should be in form of:

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

(adjust Cypher query to your needs)
Response will be JSON object with data section containing actual results.

Related