This section provides comprehensive documentation for the Azure Virtual Machines REST API. You can use this API to programmatically manage your virtual machines, including creating, configuring, starting, stopping, and deleting them.

API Operations

GET

Virtual Machines - List All

/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines

Gets a list of all virtual machines in the specified subscription.

Parameters

Name Type Required Description
subscriptionId string Yes The ID of the target subscription.
statusOnly string No Allows fetching of virtual machines based on status. Possible values are 'Provisioned' and 'Deallocated'.

Responses

Code Description
200 OK The request has succeeded. Returns a list of Virtual Machines.
400 Bad Request The request is invalid.

Example Request

GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Compute/virtualMachines?api-version=2020-06-01
            
GET

Virtual Machines - Get

/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}

Display information about the virtual machine specified by vmName.

Parameters

Name Type Required Description
subscriptionId string Yes The ID of the target subscription.
resourceGroupName string Yes The name of the resource group.
vmName string Yes The name of the virtual machine.
expand string No The expand expression to apply to the operation. For example, 'instanceView=true' can be used to get the instance view of the virtual machine.

Responses

Code Description
200 OK The request has succeeded. Returns the Virtual Machine details.
404 Not Found The Virtual Machine was not found.

Example Request

GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2020-06-01&expand=instanceView
            
PUT

Virtual Machines - Create Or Update

/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}

Create or update a virtual machine.

Parameters

Name Type Required Description
subscriptionId string Yes The ID of the target subscription.
resourceGroupName string Yes The name of the resource group.
vmName string Yes The name of the virtual machine.

Request Body

A JSON object representing the Virtual Machine resource.

Responses

Code Description
200 OK The Virtual Machine was updated successfully.
201 Created The Virtual Machine was created successfully.
400 Bad Request The request is invalid.

Example Request

PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2020-06-01
            

Example Request Body

{
  "location": "eastus",
  "properties": {
    "hardwareProfile": {
      "vmSize": "Standard_DS1_v2"
    },
    "storageProfile": {
      "imageReference": {
        "publisher": "MicrosoftWindowsServer",
        "offer": "WindowsServer",
        "sku": "2019-Datacenter",
        "version": "latest"
      },
      "osDisk": {
        "createOption": "FromImage",
        "managedDisk": {
          "storageAccountType": "Standard_LRS"
        }
      }
    },
    "osProfile": {
      "computerName": "myVM",
      "adminUsername": "azureuser",
      "adminPassword": "Password123!"
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myNic",
          "properties": {
            "primary": true
          }
        }
      ]
    }
  }
}
            
DELETE

Virtual Machines - Delete

/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}

Delete a virtual machine.

Parameters

Name Type Required Description
subscriptionId string Yes The ID of the target subscription.
resourceGroupName string Yes The name of the resource group.
vmName string Yes The name of the virtual machine.

Responses

Code Description
200 OK The Virtual Machine was deleted successfully.
204 No Content The request has been completed, but there was no content to return.
404 Not Found The Virtual Machine was not found.

Example Request

DELETE https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2020-06-01
            

Common Operations

Start Virtual Machine

Starts a virtual machine.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start
        

Stop Virtual Machine

Stops a virtual machine.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/powerOff
        

Restart Virtual Machine

Restarts a virtual machine.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/restart
        

Deallocate Virtual Machine

Deallocates a virtual machine, releasing its compute resources.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate
        

Further Reading