Skip to content

Instantly share code, notes, and snippets.

@BryantAvey
Last active March 29, 2023 09:22
Show Gist options
  • Save BryantAvey/757e09bb749ae13830382758e0c0fc06 to your computer and use it in GitHub Desktop.
Save BryantAvey/757e09bb749ae13830382758e0c0fc06 to your computer and use it in GitHub Desktop.
Power Query to import Neo4j data using named properties in a Cypher query. Uses the Jolt HTTP API header setting.
//Use Neo4j's jolt formating with the HTTP API to get properties
//This Power Query uses Accept Header "application/vnd.neo4j.jolt" in the API Call, which makes for a cleaner and shorter PQ query
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 (a)-[r:IN_CATEGORY]-(c) RETURN id(r) as RelationshipId, id(a) as ArticleNodeId, id(c) as CategoryNodeId, type(r) as RelationshipName",
// This step makes the HTTP API call to Neo4j to return data in JSON format.
Neo4jResults =
Table.PromoteHeaders(Table.SplitColumn(Table.TransformColumns(Table.RemoveLastN(Table.FromColumns({Lines.FromBinary((Web.Contents(__Neo4jURL & "/db/" & __Neo4jDatabase & "/tx/commit",
[
Headers =
[
#"Content-Type"="application/json",
#"Accept"="application/vnd.neo4j.jolt",
#"Authorization"="Basic " & Binary.ToText(Text.ToBinary(__Username & ":" & __Password, null, null)),
#"X-Stream"="true"
],
Content = Text.ToBinary("{""statements"": [ {""statement"": """ & __CypherQuery & """ } ] }")
]
)), null,null,1252)}), 2),{{"Column1", each Text.BetweenDelimiters(_, "[", "]"), type text}}), "Column1", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)), [PromoteAllScalars=true])
in
Neo4jResults
@BryantAvey
Copy link
Author

I updated this Power Query Script to have a single applied Step of "Neo4jResults" by combining all the subsequent steps to simplify the template for reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment