I have implemented a workflow, where you can basically divide a number in half and hit an API till you get the desired result .
{“nodes”: [{“parameters”: {},“id”: “286e0efc-9283-4279-bf6e-3d60dd22dc8b”,“name”: “Start”,“type”: “n8n-nodes-base.manualTrigger”,“typeVersion”: 1,“position”: [240,384]},{“parameters”: {“assignments”: {“assignments”: [{“id”: “globalVar”,“name”: “=globalVar”,“value”: “={{ $json.globalVar !== undefined ? $json.globalVar : 100 }}”,“type”: “number”},{“id”: “attempt”,“name”: “attempt”,“value”: “={{ $json.attempt !== undefined ? $json.attempt : 1 }}”,“type”: “number”}]},“options”: {}},“id”: “922bf361-0814-495d-ab38-2020a8d3c8d3”,“name”: “Initialize Variable”,“type”: “n8n-nodes-base.set”,“typeVersion”: 3.4,“position”: [464,384]},{“parameters”: {“url”: “=https://jsonplaceholder.typicode.com/todos/1”,“options”: {}},“id”: “c503d3c0-8fd0-42c4-bacb-f4943d051230”,“name”: “Call API”,“type”: “n8n-nodes-base.httpRequest”,“typeVersion”: 4.4,“position”: [688,384]},{“parameters”: {“conditions”: {“options”: {“caseSensitive”: true,“leftValue”: “”,“typeValidation”: “strict”,“version”: 3},“conditions”: [{“id”: “status-check”,“leftValue”: “={{ $json.status }}”,“rightValue”: “success”,“operator”: {“type”: “string”,“operation”: “equals”}}],“combinator”: “and”},“options”: {}},“id”: “c0238466-b97c-4ade-9422-9cbfbc8447c2”,“name”: “Check Response”,“type”: “n8n-nodes-base.if”,“typeVersion”: 2.3,“position”: [912,304]},{“parameters”: {“assignments”: {“assignments”: [{“id”: “result”,“name”: “result”,“value”: “API call successful”,“type”: “string”},{“id”: “finalValue”,“name”: “finalValue”,“value”: “={{ $json.globalVar }}”,“type”: “number”}]},“options”: {}},“id”: “ceb8af88-9d0b-4eb0-9219-92088d3d7798”,“name”: “Success - Stop”,“type”: “n8n-nodes-base.set”,“typeVersion”: 3.4,“position”: [1136,208]},{“parameters”: {“assignments”: {“assignments”: [{“id”: “globalVar”,“name”: “globalVar”,“value”: “={{ $(‘Initialize Variable’).item.json.globalVar /2}}”,“type”: “number”},{“id”: “attempt”,“name”: “attempt”,“value”: “={{ $(‘Initialize Variable’).item.json.attempt +1}}”,“type”: “number”}]},“options”: {}},“id”: “226e6ce1-7e10-47b6-b7fc-1a26054e8a08”,“name”: “Halve Variable”,“type”: “n8n-nodes-base.set”,“typeVersion”: 3.4,“position”: [1136,400]},{“parameters”: {“mode”: “runOnceForEachItem”,“jsCode”: “// Pass data forward for next iteration\nreturn { globalVar: $input.item.json.globalVar, attempt: $input.item.json.attempt };”},“id”: “1f0c7da9-d019-41da-8dc5-96875202c1cf”,“name”: “Prepare Retry”,“type”: “n8n-nodes-base.code”,“typeVersion”: 2,“position”: [1360,480]}],“connections”: {“Start”: {“main”: [[{“node”: “Initialize Variable”,“type”: “main”,“index”: 0}]]},“Initialize Variable”: {“main”: [[{“node”: “Call API”,“type”: “main”,“index”: 0}]]},“Call API”: {“main”: [[{“node”: “Check Response”,“type”: “main”,“index”: 0}]]},“Check Response”: {“main”: [[{“node”: “Success - Stop”,“type”: “main”,“index”: 0}],[{“node”: “Halve Variable”,“type”: “main”,“index”: 0}]]},“Halve Variable”: {“main”: [[{“node”: “Prepare Retry”,“type”: “main”,“index”: 0}]]},“Prepare Retry”: {“main”: [[{“node”: “Initialize Variable”,“type”: “main”,“index”: 0}]]}},“pinData”: {},“meta”: {“instanceId”: “0f39d8fdd402ddce20d0eb724526828e8c2d8679170e3a08fe6cd471c799fab6”}}
See if this helps