Cannot pass a variable into the run method of Neo4j Python Driver

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)

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.

Screen Shot 2022-12-27 at 11.35.46 PM.png

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

Each statement in your file must terminate with a semicolon.

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.