Whats the best way to handle this

I have an API I am getting data from, and as usual it has a limit, this time 250 per call however I do get some data to help repeat through.
This is what that data looks like

data": {
      "totalSize": 3289,
      "done": false,
      "nextRecordsUrl": "/services/data/v53.0/query/01g3K123456KqzJMQAZ-250",
      "records": Array[250][
        {...}
      ]
}

I really do not want to have to duplicate all my steps 14 times to get to the final 3289 so I can add all the records to my internal database.

totalSize is the same throughout
done changes to true when there is no nextRecordsUrl
nextRecordsUrl ends with -250 and the entire code before that remains the same for every page

Surely there must be a smart way to repeat through all these

Currently my steps look like this
2021-10-02_00-21-48

Pretty simple, call the API, repeat through each record of the Array, check if the record already exists in the database, if it does update it, if it doesn’t insert it.

Anyone got any bright maths ideas

Community Page
Last updated: