Share via

virtual machine deprovision REST API error

Daniele Perrotta 1 Reputation point
2022-08-26T14:27:28.113+00:00

dear all,

in order to delete a virtual machine, I call the follow API:

Method: DELETE
URL:
https://management.azure.com/subscriptions/xxxxxxxxxxxxxx/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/vmName1?api-version=2022-03-01

I received the follow error:

409: { "error": { "code": "OperationNotAllowed", "message": "Disk XXXXX_aa8411492c1345bf95539ff88f408851 is attached to VM /subscriptions/XXXXXX/resourceGroups/XXXXX/providers/Microsoft.Compute/virtualMachines/YYYYYY"}}

this error regards to the boot disk which is attached anymore.

So I have tried to launch the same API and method with the forceDeletion parameter but the error occours

Does anyone know why?
furthermore, does anyone know the right method and api to deprovision a virtual machine?

thanks very much

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-08-26T20:22:33.807+00:00

    @Daniele Perrotta

    I understand you are wanting to delete a VM via REST API but are running into the above error. Can you try running detach disk and then running the delete?

    You need to run VM update first to detach the disk. You can find a sample here which is using the data disk.

    Please try this and let me know if it works for you.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.