Skip to content

Instantly share code, notes, and snippets.

@BryantAvey
Last active May 17, 2021 21:03
Show Gist options
  • Save BryantAvey/f19d24abfc4dc0697d16ce1a1c820d5e to your computer and use it in GitHub Desktop.
Save BryantAvey/f19d24abfc4dc0697d16ce1a1c820d5e to your computer and use it in GitHub Desktop.
Import Neo4j Nodes Data to Power BI. This power query uses the default HTTP API to get nodes only data from Neo4j.
// This Power Query script connects to Neo4j and runs a Cypher query that returns node objects.
// Get Nodes
let
//Enter the base URL for the Neo4j Server
__Neo4jURL = "http://localhost:7474",
// Enter the name of the database in Neo4j
__Neo4jDatabase = "blogs",
// Enter the username for database access in the Neo4j database
__Username = "neo4j",
// Enter the user password for databases in the Neo4j database
__Password = "demo",
// Enter a Cypher Query returning full nodes.
__CypherQuery = "MATCH (n:Article) RETURN n",
// This step combines several steps to simplify and reduce the steps in Power Query to return data from Neo4j.
#"Ready To Expand Rows" = Table.ExpandListColumn(
Table.ExpandRecordColumn(
Table.FromList(
Json.Document(
Web.Contents(__Neo4jURL & "/db/" & __Neo4jDatabase & "/tx/commit",
[Headers =
[#"Content-Type"="application/json",
#"Authorization"="Basic " & Binary.ToText(Text.ToBinary(__Username & ":" & __Password, null, null)),
#"X-Stream"="true"
],
Content = Text.ToBinary("{""statements"": [ {""statement"": """ & __CypherQuery & """ } ] }")
]
) // This is the end of the Web.Contents container that makes the Neo4j HTTP API POST call.
) // This completes the Json.Document container wrapper that converts the Neo4j HTTP API call to a JSON document.
[results]{0}[data], //This completes the Table.FromList() parameters
Splitter.SplitByNothing(), //This completes the Table.FromList() parameters
null, null, ExtraValues.Error), //This completes the Table.FromList() parameters
"Column1", {"row"}, {"row"}),"row" //This completes the Table. ExpandedRecordColumn() parameters
)
in
#"Ready To Expand Rows"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment