Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-27-2022 02:55 PM
In the below code i want to pass variables from the run method of Neo4j Python Driver to the query and then forward these variables to the specific cypher file with the runFile method.
The problem is that the variables url and apiKey are not passed to the query (or not forwarded to the file (?)) when they defined as variables. However when they are passed as strings 'https://services.nvd.nist.gov/rest/json/cpes/2.0' for example the url, everything works pretty good and the nodes i want are created.
Any thoughts??
def getData(self, url, apiKey):
print("\nInserting CPE Files to Database...")
# Insert file with CPE Query Script to Database
query = """call apoc.cypher.runFile("CPE.cypher", {parameters: {APIurl: $APIurl, ParameterName: $ParameterName,
ParameterValue: $ParameterValue, AuthKey: $AuthKey}})"""
session = self.driver.session()
result = session.run(query, APIurl = url, ParameterName = 'startIndex', ParameterValue = '0', AuthKey = apiKey)
print(result)
Solved! Go to Solution.
01-11-2023 09:37 AM
As always the problem was on the dev side and not on the application - platform side.
url and apiKey variables that were passed included ' ' at the 0 and last index of the string. A simple cut of these was enough to pass the variables to neo4j and work as it should.
12-27-2022 08:38 PM
Can you share a few lines of your CPE.cypher file?
I looked at the runFile source code. It looks like eventually each statement is executed separately with a 'tx.execute(cypher, params)' statement, with the params as a map containing the parameters passed to the 'runFile' procedure.
Are you referencing the parameters in your file with a '$' prefix? I was able to get it to work with the following single line cypher file:
return $APIurl as api_url, $ParameterName as param_name, $ParameterValue as param_value, $AuthKey as auth_key;
It returned the values I had passed as parameters.
12-28-2022 12:32 AM
These are the first lines of the CPE.cypher.
WITH $APIurl + '?' + $ParameterName + '=' + $ParameterValue AS url,
$AuthKey AS apiKey
call apoc.load.jsonParams(url, { apiKey : apiKey }, null ) yield value
12-28-2022 06:08 PM
Each statement in your file must terminate with a semicolon.
01-11-2023 09:37 AM
As always the problem was on the dev side and not on the application - platform side.
url and apiKey variables that were passed included ' ' at the 0 and last index of the string. A simple cut of these was enough to pass the variables to neo4j and work as it should.
All the sessions of the conference are now available online