Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-25-2020 09:49 PM
Greetings,
I was able to write a complex query using five to six cypher statements. I want to parameterize this query and call it from HTTP API. What is the best way to do this ?
match (c:Company {name: "ABC"})-[:company_to_order]-(f:Order)<-[:market_to_order]-(m:Market {name: "CRPTPA"})
match (f)<-[:orderbasis_to_order]-(fb:OrderBasis {name: f.class}) with f,c, fb
match (ft:OrderTariff {name: f.tariff}) with f, ft,c,fb
match (ft)-[:ordertariff_to_orderruletariff]-(frt:OrderRuleTariff) with f, ft, frt,c,fb
match (frt)-[:orderruletariff_to_record0]-(r0:Record0)<-[:company_to_record0]-(c) with f,ft,frt,c,fb,r0
match (c)-[:company_to_record1]-(r1:Record1)<-[:orderbasis_to_record1]-(fb) with f,ft,frt,c,fb,r0,r1
match (frt)-[:orderruletariff_to_record1]-(r1) with f,ft,frt,c,fb,r0,r1
return f,ft,frt,fb,r0,r1
I want to be able to pass company name and market name each time I invoke this set of statements that return a result set.
My end goal is to invoke this from HTTP REST end point.
please can you let me know the best way to achieve this.
Thanks
Solved! Go to Solution.
04-26-2020 01:09 AM
Hope this would help.
URL: http://localhost:7474/db/data/transaction/commit
Method: post
Add Authorization header with Basic token
body
{
"statements":
[{
"statement": "<query as string>"
},
"parameters" : {
"country" : "es"
}
]
}
Examples: https://stackoverflow.com/questions/22276795/how-do-you-use-parameters-with-neo4j
Doc: https://neo4j.com/docs/http-api/3.5/actions
Thanks
04-26-2020 01:09 AM
Hope this would help.
URL: http://localhost:7474/db/data/transaction/commit
Method: post
Add Authorization header with Basic token
body
{
"statements":
[{
"statement": "<query as string>"
},
"parameters" : {
"country" : "es"
}
]
}
Examples: https://stackoverflow.com/questions/22276795/how-do-you-use-parameters-with-neo4j
Doc: https://neo4j.com/docs/http-api/3.5/actions
Thanks
04-26-2020 08:13 AM
Thank you @ganesh.sharma679.
I was able to run the query from postman using the information you provided above. Thanks again.
Does it pass the values from one statement to other statement ? If not, Is there a way to pass the values from the first statement to second and so forth.
In the example below I want to use the return value p from the first statement in the second statement. Looks like it is not using that value based on my results from the test I did against the Movie database.
Request:
{
"statements" : [ {
"statement" : "MATCH (p:Person {name: $actor}) RETURN p",
"parameters" : {
"actor" : "Tom Hanks"
}
},
{
"statement" : "MATCH (p)-[:ACTED_IN]->(m:Movie) RETURN p as Actor ,m as Movie limit 3",
"parameters": {
"nodeId" : 7
}}]
}
Response:
{
"results": [
{
"columns": [
"p"
],
"data": [
{
"row": [
{
"born": 1956,
"name": "Tom Hanks"
}
],
"meta": [
{
"id": 71,
"type": "node",
"deleted": false
}
]
}
]
},
{
"columns": [
"Actor",
"Movie"
],
"data": [
{
"row": [
{
"born": 1978,
"name": "Emil Eifrem"
},
{
"tagline": "Welcome to the Real World",
"title": "The Matrix",
"released": 1999
}
],
"meta": [
{
"id": 8,
"type": "node",
"deleted": false
},
{
"id": 0,
"type": "node",
"deleted": false
}
]
},
{
"row": [
{
"born": 1961,
"name": "Laurence Fishburne"
},
{
"tagline": "Welcome to the Real World",
"title": "The Matrix",
"released": 1999
}
],
"meta": [
{
"id": 3,
"type": "node",
"deleted": false
},
{
"id": 0,
"type": "node",
"deleted": false
}
]
},
{
"row": [
{
"born": 1960,
"name": "Hugo Weaving"
},
{
"tagline": "Welcome to the Real World",
"title": "The Matrix",
"released": 1999
}
],
"meta": [
{
"id": 4,
"type": "node",
"deleted": false
},
{
"id": 0,
"type": "node",
"deleted": false
}
]
}
]
}
],
"errors": []
}
04-26-2020 08:49 AM
I changed my request to have all the cypher statements in one statement and seems like I can put it all in one statement in the request as shown below. It is working great except I have the following follow up question.
Anyone know how to eliminate the following meta with nulls in the response. It is returning this for every row of the data that gets returned.
"meta": [
null,
null,
null,
null,
null
]
Request:
{
"statements" : [ {
"statement" : "MATCH (p:Person {name: $actor}) WITH p MATCH (p)-[:ACTED_IN]->(m:Movie) RETURN p.name as Actor, p.born as Born ,m.title as Movie, m.released as Release, m.tagline as TagLilne limit 3",
"parameters" : {
"actor" : "Tom Hanks"
}
}]
}
Response:
{
"results": [
{
"columns": [
"Actor",
"Born",
"Movie",
"Release",
"TagLilne"
],
"data": [
{
"row": [
"Tom Hanks",
1956,
"A League of Their Own",
1992,
"Once in a lifetime you get a chance to do something different."
],
"meta": [
null,
null,
null,
null,
null
]
},
{
"row": [
"Tom Hanks",
1956,
"Cloud Atlas",
2012,
"Everything is connected"
],
"meta": [
null,
null,
null,
null,
null
]
},
{
"row": [
"Tom Hanks",
1956,
"The Da Vinci Code",
2006,
"Break The Codes"
],
"meta": [
null,
null,
null,
null,
null
]
}
]
}
All the sessions of the conference are now available online