Using Desktop 1.4.1 with a 4.2.0 database...
I am trying to get paginated results from an API using apoc procedures.
I have seen the Zendesk example from @dana_canzano as well as some other threads but I just can't seem to get the right code to work. Below is my code using a temp node to store the "next url" to paginate to similar to the Zendesk example.
WITH {Authorization: 'key ' + apoc.static.get('api.key') } AS headers
CALL apoc.periodic.commit('
**3** MATCH (tn:TempNode {id: 1})
WITH tn, headers
CALL apoc.load.jsonParams(tn.url, headers, null)
YIELD value as value
WITH tn, headers, value, value.next as next_url
FOREACH (result in value.results |
MERGE (s:Set {id:result.set_num})
SET s.url = result.set_url,
**11** s.img = result.set_img_url)
WITH next_url, headers
CASE WHEN next_url is NULL then 0 ELSE 1 END AS count
FOREACH(_ in CASE WHEN count = 0 THEN [] ELSE[1] END |
MERGE (tn:TempNode {id:1})
SET tn.url = next_url
)
RETURN count(*) '
, null);
The logic in lines 3 thru 11 will work fine if i don't CALL apoc.periodic.commit
. My headers also work fine. So something seems to happen when trying to reset the tn.url
parameter to get the next url to begin the process again for the next 1000 sets. I have tried many iterations to get it to work. As of now, the code errors out with a " Query cannot conclude with CALL (must be RETURN or an update clause)
" Yet I do not see any other RETURN lines in Zendesk or other examples. So, do I have a typo somewhere? Has the 4.2.0 update changed something? I have spent all day trying to get this to work without success. Any help would be appreciated by a fresh set of eyes. Thanks.