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

apoc

(Chris Bautista) #1

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?


(Michael Hunger) #2

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

(Chris Bautista) #3

This is exactly what I needed. Thanks!