mangesh
mangesh

Reputation: 521

Azure Virtual Machine DELETE API returning HTTP 204 instead of 404

I am using the following API: https://learn.microsoft.com/en-us/rest/api/compute/virtualmachines/delete

When trying to delete a VM which does not exist, I am given this response:

Response Code: 204

Headers- cache-control: no-cache expires: -1 pragma: no-cache x-ms-correlation-request-id: 0bda7be7-6f2a-4202-9565-04d16c210606 x-ms-ratelimit-remaining-subscription-deletes: 14996 x-ms-request-id: 0bda7be7-6f2a-4202-9565-04d16c210606 x-ms-routing-request-id: WESTINDIA:20181223T044056Z:0bda7be7-6f2a-4202-9565-04d16c210606

Body: null

Shouldn't ideally a HTTP 404 be returned?

Upvotes: 0

Views: 418

Answers (1)

Itay Podhajcer
Itay Podhajcer

Reputation: 2656

I suggest you take a look at Track asynchronous Azure operations to better understand the flow of execution when using Azure's management APIs.

As far as I understand, you are getting a 204 because the operation doesn't complete immediately. If you want to check the operation's state and end result, you need to query for it using methods described in the above link.

Update

After trying the operation on one of my subscriptions, looking at portal's activity log, it seems that the operation is being logged as "Succeeded". I'm afraid that the only way to know if a VM exists or not, is by trying to query for its info.

I also think, that in previous versions of the API a 404 was being returned in case the VM was not found, but for some reason it was changed (maybe because if it is not found then it already in a "deleted state").

Hope it helps!

Upvotes: 3

Related Questions