We are migrating to version 2 of the API and, on rare occasions, we are seeing the following odd behavior:
At the end of a 4 hour time slot our application requests a new token and receives it without problems. The token is used to generate a new key.
Immediately after generating the new key, our application attempts to retrieve account information. The attempt fails due to receiving an "Invalid Key" error from Toodledo's server. The scheduled sync is aborted.
One hour later, at the next scheduled sync, our application tries again to get account information using the exact same key. This time it succeeds. All remaining API calls for the scheduled sync have no issues.
Using the online tool in the API documentation, I have double-checked to make sure that our application is generating the correct key.
Nothing is changing at the Toodledo account during this time. The password is the same.
The problem only occurs right after a new token is obtained. It has not happened in the middle of the 4 hour time slot.
Any ideas what could cause the Toodledo server to reject a key at one point and then accept the same key an hour later?
Im not really sure what could cause this. I suppose it could be a timing issue. If your app is really really fast it could try to use the new token before that token has replicated to all of our database servers. Can you try an experiment? Put a 2 second delay in between getting a token, and using it. If that fixes the problem then let me know and I'll see if we can get around this on our end by having token validation use the master db instead of the replicas.
I've adjusted the software to delay for 2 seconds after receiving an "Invalid Key" error, and then try again. If the second attempt succeeds, then we will know that your theory about the database updates is correct. This problem doesn't happen very often, so it may take a few days to see if this is the case. I'll let you know.