How to pass paremeter for apoc.export.csv.query?

Hello,

I am trying to send data from a CSV file to apoc query in python.
My query looks like follows:

 """
               
                CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item', Name:$CI_name}) --(ev:Event)--(c:Common)
                optional match (c)--(ev_c:Event)--(en:Entity)
                where en.EntityType='Change' or en.EntityType='Interaction'
                with  en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
                order by ev.Start where not ent='null'
                return collect(act), ID, ent", "results.csv",{stream:true, params:{CI_Name:$CI_name}})
                """

and the Python code which sends the data is as follows:

with open ('CI.csv','r') as first_file:
    csv_f = csv.DictReader(first_file)
    for row in csv_f:
        counter(row["n.Name"])

However, I am getting the following error

*raise CypherError.hydrate(*metadata)
neobolt.exceptions.ClientError: Expected parameter(s): CI_name

Could you help me with fixing this?

Thanks,

Pinar.

Hi @pinartyilmaz,

Welcome to the community!!

How are you passing parameter value for parameter variable CI_name in your code?

Thank you for your reply!
As I shared in the previous post, the following python code is sending the parameter for CI_name:

with open ('CI.csv','r') as first_file:
    csv_f = csv.DictReader(first_file)
    for row in csv_f:
        counter(row["n.Name"])

and then the following code is processing it:

def counter(CI_name):
    driver = GraphDatabase.driver(uri, auth=("neo4j", "BPI14"))
    with driver.session() as session:
        session.run(
                """
               
                CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item', Name:$CI_name}) --(ev:Event)--(c:Common)
                optional match (c)--(ev_c:Event)--(en:Entity)
                where en.EntityType='Change' or en.EntityType='Interaction'
                with  en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
                order by ev.Start where not ent='null'
                return collect(act), ID, ent", "results.csv",{stream:true, params:{CI_Name:CI_name}})
                """
                )
  1. Kindly try to execute the export query from the browser itself.
  2. Secondly, you have used two versions of parameter name CI_Name/CI_name

Thank you for pointing out the parameter name issue! However, even though I changed it, I am still getting the same error. The query is working well in the browser.
I just want to clarify that I already added the following line in the log:
apoc.export.file.enabled=true

Insert a forward slash before the file name:

return collect(act), ID, ent", "/results.csv"

Hi, thank you for your comment! I tried but it did not solve my problem, I am still getting the same error.

I guess the problem is how to pass parameter CI_name from function parameter to the cypher query. Could you please try referring the below link

1 Like

Thank you so much! That solved my problem!
I changed the code as following:

query="""  
          
                CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item'}) --(ev:Event)--(c:Common)
                where n.Name='%s'
                optional match (c)--(ev_c:Event)--(en:Entity)
                where en.EntityType='Change' or en.EntityType='Interaction'
                with  en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
                order by ev.Start where not ent='null'
                return collect(act), ID, ent", "/results_test.csv",{stream:true})
                """
    query = query % (CI_name)
    graph.run(query)