How to pass parameters in APOC functions?

what is wrong with
CALL apoc.export.csv.query("RETURN last", "export/EndpointQueries.csv", {params: {last:'xyz'}}) ?

I keep getting an error "variable last not defined".

I think someone already answered you on the users slack, but parameter usage in a query requires the parameter to be prefixed with $, so RETURN $last should work.

You may be used to working with apoc.periodic.iterate(), and for the updating inner query for convenience we expose the parameters from the outer query as variables, which is why you may not have seen usage of parameter syntax there.

I really have trouble with the following:

I have a file "EndpointQueries.csv":

:param Lastname => 'Rossi'; 

:param Firstname => 'R'; 

CALL apoc.export.csv.query("
RETURN $Last as last2, $First as first2", "export/EndpointQueries.csv", {params: {Last: $Lastname, First: $Firstname} } )

;

When I execute the lines in browser, I do create the file EndpointQueries.csv

But, when I run the following command in terminal:
cat scripts/EndpointQueries.cql | ../bin/cypher-shell -u neo4j -p admin123 > outputs/EndpointQueries.log, EndpointQueries.csv is not created.

It looks like cypher-shell is sensitive to trailing spaces after the semicolons, I kept getting this error when attempting the command:

Invalid input 'A': expected whitespace, comment, Statement or end of input (line 1, column 18 (offset: 17))

Seems misleading, but once I got rid of the trailing whitespaces it executed fine.

Also, make sure you have this in your neo4j.conf:

apoc.export.file.enabled=true

@andrew_bowman I do have apoc.export.file.enabled=true flag on conf file.

However, currently the following cypher shell command

cat scripts/EndpointQueries.cql | ../bin/cypher-shell -u neo4j -p admin123  > outputs/EndpointQueries.log

where $ cat scripts/EndpointQueries.cql

CALL apoc.export.csv.query("RETURN 'kannan' as last2, 'lavanya' as first2", "export/EndpointQueries.csv", {});

is not producing the csv file. On the other hand, the browser version does produce the csv file. Is there something I am missing. I used to be able to run cypher shell commands that build csv s - do you suspect something might have changed in the conf file?

Thanks,
Lavanya

1 Like