When I create a snapshot via API it returns an ID which I then store in my database. But when I list my snapshots later they all have different ID’s, is the snapshot ID changing over time or does the API return the wrong ID for some reason? are there any workarounds to this problem?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi @chadlwilliams, As @hansen already said, when you execute Snapshot actions, it returns an action ID, not a snapshot ID. API docs states it:
It’s not wrong ID, it’s just an action ID which you can use to ‘trace’ snapshot execution. Until creation is not complete, you will not have snapshot ID.
Action ID alongside Action endpoints is used to check action (in your case snapshot) details. You can learn more about it in API docs: Retrieve a Droplet Action or Retrieve an existing Action. There is result difference between above two, but
Retrieve a Droplet Action
requires you to provide Droplet ID whileRetrieve an existing Action
doesn’t.When you query any of above Action endpoints, you get
status
of Action as well as other important details. If creation is in progress, status will bein-progress
. Once it completes (successfully), it will becompleted
Workaround is to query Action endpoint, with ID you got when executed snapshot request, until progress is not
in-progress
. Once it iscompleted
, execute Get Snapshot to obtain its ID. Reason why we check is it notin-progress
is we don’t know whatstatus
will be in case of fail, so you don’t risk stuck-ing into infinity loop. For example, something similar happens indoctl
. It is querying Action endpoint every 5 seconds until Actions status is notin-progress
. If you are more interested in it, you can see how doesactionWait
code looks like on GitHub.Only thing you could pay attention here is rate limit. Rate limit is how much API requests you can execute per time unit. Once remaining rate limit reaches zero, you will not be able to execute API requests until limit restarts. API docs states that it’s currently limited to 5,000 requests per hour per token.
In most of cases you are safe, but for example if you are checking status for 10 snapshots in same time every 5 seconds, you can run out of it. If you get in problem like this, just raise time and you will be good to go.
If you get into any problem, feel free to ask anything. Maybe I went to much into details, but hopefully it will be helpful to you.
This is a SUPER stupid concept. It should definitely return the snapshot id at creation time, with a status like pending, processing, success…
With this stupid concept, how can I map the snapshots from API to my application object model? The answer is:
By following this flow, from my end, I’ll have to make sure that my app won’t accept any other snapshot creation request if the latest action status is “in-progress”.
And here is the flow if DO returns snapshot id at creation time:
And the best way should be using webhooks.