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.

Error handling apoc.load.json when called from apoc.periodic.iterate

Error
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedureapoc.load.json: Caused by: java.lang.RuntimeException: Can't read URL or key {$url} as json: {$url}

Statement

CALL apoc.periodic.iterate("
  MATCH (n)
  RETURN n as node
", "
  CALL apoc.load.json($url +  node.someId + '/' + node.someValue) YIELD value as v
  // Problem is that some of the URLs will return 404
  RETURN v
",
"
  params: {
    url: "someUrl"
  }
")

Description

  • I am reading some nodes that contain information about data stored in a rest API using apoc.periodic.iterate
  • Then for every node, I will make a call to the API using apoc.load.json
  • The error occurs when the API is returning a 404 for some of the URLs causing the entire statement to fail
  • It appears that my data source has missing data and I would like to skip the 404s and continue with the iterate.

What is the best way to handle an error when calling apoc.load.json on a 404 during an apoc.periodic.iterate so that I can skip the bad URLs?

1 ACCEPTED SOLUTION

There is an option for apoc.load.jsonParams to ignore missing files.

apoc.load.jsonParams('url',{header:value},payloadOrNull, {failOnError:false}) YIELD value - load from JSON URL (e.g. web-api) while sending headers / payload to import JSON as stream of values if the JSON was an array or a single value if it was a map

View solution in original post

4 REPLIES 4

There is an option for apoc.load.jsonParams to ignore missing files.

apoc.load.jsonParams('url',{header:value},payloadOrNull, {failOnError:false}) YIELD value - load from JSON URL (e.g. web-api) while sending headers / payload to import JSON as stream of values if the JSON was an array or a single value if it was a map

This is exactly what I needed. Thanks!

I am trying to execute following cypher
call apoc.load.jdbc('jdbc:sqlserver://xxxxx','exec tempProcedure[department]') YIELD row with row.displayName as data call apoc.load.json(data) yield value return value

getting below error
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure apoc.load.json: Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: [{"target_table":"xxx","source_table":"yyy","source_column_name":"abc","weight":1,"Neo_Relationship_Name":"FUNCTIONAL_UNIT_AT"}]

Can anyone help me on this

data needs to be an URL, are you sure it is? Or did you just miss to add the URL prefix to apoc.load.json?

something like:

call apoc.load.jdbc('jdbc:sqlserver://xxxxx','exec tempProcedure[department]') 
YIELD row with row.displayName as data 
call apoc.load.json("http://host/path?q="+data) 
yield value return value