# apoc.load.jsonParams within apoc.periodic.commit for API retrieval

**URL:** <https://community.neo4j.com/t/apoc-load-jsonparams-within-apoc-periodic-commit-for-api-retrieval/33173>\
**Category:** Procedures & APOC\
**Tags:** apoc\
**Created:** [February 3, 2021, 11:06pm UTC](https://community.neo4j.com/t/apoc-load-jsonparams-within-apoc-periodic-commit-for-api-retrieval/33173 "2021-02-03T23:06:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FourMoBro](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/fourmobro/32/30171_2.png) [@FourMoBro](https://community.neo4j.com/u/FourMoBro)\
**Post date:** [February 3, 2021, 11:06pm UTC](https://community.neo4j.com/t/apoc-load-jsonparams-within-apoc-periodic-commit-for-api-retrieval/33173/1 "2021-02-03T23:06:51Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [February 4, 2021, 12:08am UTC](https://community.neo4j.com/t/apoc-load-jsonparams-within-apoc-periodic-commit-for-api-retrieval/33173/2 "2021-02-04T00:08:13Z")

</div>

trying to get this to work with 4.2.3 and having issues

```auto
    WITH next_url, headers
    CASE WHEN next_url is NULL then 0 ELSE 1 END AS count

```

should be

```auto
    WITH next_url, headers, 
    CASE WHEN next_url is NULL then 0 ELSE 1 END AS count

```

note the trailing `,` after `headers`

further I did just to see if I could get it to progress changed

```auto
    RETURN count(*) '
    , null)

```

to

```auto
    RETURN count(*) '
    , null)
yield updates return count(*);

```

and then it complained that it didnt like `with tn, headers` from line 4 and that `headers` was not defined. I then tried to move line 1 to the 1st line of apoc.periodic.comit and then had further errors.

maybe the above will get you closer

yield updates return count(\*);

---

<div class="post-metadata">

**Author:** ![FourMoBro](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/fourmobro/32/30171_2.png) [@FourMoBro](https://community.neo4j.com/u/FourMoBro)\
**Post date:** [February 4, 2021, 12:45am UTC](https://community.neo4j.com/t/apoc-load-jsonparams-within-apoc-periodic-commit-for-api-retrieval/33173/3 "2021-02-04T00:45:17Z")

</div>

Well, it is refreshing, I guess to see you struggle with it as well. I tried your suggestions and few more things....switching FOREACH to UNWIND, etc. but I still can't find the right mixture. Maybe it is a 4.\* issue and I should stop for the time being.
