How to code auto-retry for API call

First you should save the data somewhere in your wordpress. I personally like to use custom tables. Then use a schedule (cron job) to check if there is new data. Then try to submit the data. If you sumitted the data successfully delete it or mark your local data as successfully submitted. Else retry it with the next schedule run. If you want to increase the waiting time with every try you could save the retry count on your local dataset.