Hi Forrest Wu,
Prerequisites: Azure subscription, VM resource(Details: SubscriptionID, resourceGroupName, vmName), Service Principal or Managed Identity with the required permissions, Access Token (Via Azure Active Directory).
Get an Access Token ensure that you include the correct authentication header in your request. You can use Azure AD to get the necessary bearer token.
Request:
POST https://login.microsoftonline.com/{tenantId}/oauth2/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id={clientId}
&client_secret={clientSecret}
&resource=https://management.azure.com/
You'll receive a token in the access_token field.
Request to start a VM
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2024-03-01
Headers:
Authorization: Bearer {access_token}
Content-Type: application/json
Body:
Empty (none required for this operation).
Example with curl:
curl -X POST \
"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2024-03-01" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json"
Response you will get a 202 Accepted response indicating the start operation was initiated.
https://learn.microsoft.com/en-us/rest/api/compute/virtual-machines/start?view=rest-compute-2025-02-01&tabs=HTTP
https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow
If you found information helpful, please click "Upvote" on the post to let us know.
If you have any further queries, feel free to reach out — we’re always happy to assist you.
Thank You.