cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to Use Neo4j :param in Node .Post Query

RedInk
Node Link

Howdy,

I have a cypher query inside a Node .post using call apoc.load.json($myNeo4jParam) yield value.

When I run this query I get an error Neo4jError: Expected parameter(s): myNeo4jParam. So my apoc call is not using my Neo4j database :param myNeo4jParam.

I realize I can just put the URL I want to hit here, but was hoping to use the :param, though I guess the more I think about it, I'm hard-coding either way?

How do I differentiate from a parameter passed from my client and wanting to use a :param that is in my Neo4j data?

1 ACCEPTED SOLUTION

You are correct. The 'param' is only available in the browser. In fact, it goes away when the window is closed. You will need to pass your parameter in the request. You just need to follow the format. Here is an example http request body: 

 

{
    "statements": [
        {
            "statement": "match(n:Item{key:$key}) return n.name as name",
            "parameters": {"key":212}
        }

    ]
}

 

You could also use the Neo4j JavaScript driver to execute the query directly. 

 

 

View solution in original post

5 REPLIES 5

glilienfield
Ninja
Ninja

Can you provide the code?  

I assume you are making a request via http since you are ‘posting’. If so, did you provide your request in the format outlined here:

https://neo4j.com/docs/http-api/current/actions/query-format/

it has a place to define your parameters. 

When you referenced ‘:param’, are you referring to the neo4j desktop parameters? 

Thanks @glilienfield,

Yes I'm referring to the :param that can be created in Neo4j browser (I think I'm realizing that this :param exists solely for use in the browser/desktop)...

neoparam.PNG

The fuller code trying to call the Neo4j :param is...

app.post('/createX', async (req, res) => {
  const {title} = req.body;
  try {
    const result = await session.run(`call apoc.load.json($myNeo4jParam) yield value
...

I think the answer is No, but... Is there a way to tell Nodejs to use the Neo4j :param, not a const {param} sent from the client?

Many Thanks!

You are correct. The 'param' is only available in the browser. In fact, it goes away when the window is closed. You will need to pass your parameter in the request. You just need to follow the format. Here is an example http request body: 

 

{
    "statements": [
        {
            "statement": "match(n:Item{key:$key}) return n.name as name",
            "parameters": {"key":212}
        }

    ]
}

 

You could also use the Neo4j JavaScript driver to execute the query directly. 

 

 

Thanks @glilienfield,

RE: 'Deleting :params', I just posted the question to your answer in a new post, so your answer won't be buried in this separate 'param usage' topic.

Here is a reference to the docs on the HTTP request format:

https://neo4j.com/docs/http-api/current/actions/query-format/