Azure, Cloud Computing

4 Mins Read

Operations on Virtual Machine Resource Using Azure REST API

Voiced by Amazon Polly

Introduction

We can fetch any resource details under any service in Azure using Microsoft Azure REST API of that respective resource here I have elaborated on Virtual Machine using REST API. For this, we should have four IDs that are Subscription ID, Tenant ID, Client ID, and Secret Value which are created in the App Registration process.

Customized Cloud Solutions to Drive your Business Success

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

Steps to Generate Bearer Token using Tenant ID, Client ID, Secret Value

  1. https://login.microsoftonline.com/<your tenant id>/oauth2/token
  2. Paste the above URL with your Tenant ID in Postman Application
  3. Go To Body -> select x-www-form-urlencoded and provide the below body as Key and Value pair

Ex: Provide grant_type as Key and client_credentials as Value

grant_type : client_credentials

client_id : “<your Client ID>”

client_secret : ”<your Secret Value>”

resource:https : //management.azure.com/

step3GB

4. The above API request will respond in JSON format, and we only need to pass the value of the access_token key as a token in all the REST API operations.

Steps to Create Virtual Machine using REST API

  1. Click here for the URL
  2. Paste the above URL with your subscription id present under that provided tenant id, provide any resource group name in which the machine is to be created and provide the VM name in the Postman and use the PUT method.
  3. Go to Headers and provide the below data as key and value pair.

Content-Type: application/json

Authorization: Bearer <paste the generated bearer token in the first step>

  1. Provide the below sample API Request body in the Body -> select raw.

step4vm

step4vmb

5. Sample API Request Body:

6. After completing all the above steps, the API will get processed with the API response.

7. From the response, the virtual machine will be created with the given VM name, under the samplegroup resource group, and the same configuration as you provided in the request body.

8. The created VM will get reflected in that same subscription id Azure Portal.

step8vm

Steps to List Virtual Machine by Resource Group using REST API

  1. https://management.azure.com/subscriptions/{{subscription_id}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Compute/virtualMachines?api-version=2022-08-01
  2. Paste the above URL with the same subscription id, provide the resource group name in which the machine is created in the Postman and use the GET
  3. Go To Headers and provide the below data as key and value pair.

Content-Type: application/json

Authorization: Bearer <paste the generated bearer token in the first step>

Step3RG

Steps to List All Virtual Machines by Subscription ID using REST API

  1. https://management.azure.com/subscriptions/{{subscription_id}}/providers/Microsoft.Compute/virtualMachines?api-version=2022-08-01
  2. Paste the above URL with only the same subscription id and use the GET
  3. Go To Headers and provide the below data as key and value pair.

Content-Type: application/json

Authorization: Bearer <paste the generated bearer token in the first step>

Step3sub

Steps to Deallocate the Specific Virtual Machine using REST API

  1. https://management.azure.com/subscriptions/{{subscription_id}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Compute/virtualMachines/{{vmName}}/deallocate?api-version=2022-08-01
  2. Paste the above URL with the same subscription id, provide the resource group name in which the machine is created and the VM name in the Postman, and use the POST
  3. Go To Headers and provide the below data as key and value pair.

Content-Type: application/json

Authorization: Bearer <Generate another token>

  1. The API will get processed with code 202 saying Accepted and the machine will be deallocated in some time and reflected in the Azure Portal too.

step4d

Steps to Delete the Specific Virtual Machine using REST API

  1. https://management.azure.com/subscriptions/{{subscription_id}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Compute/virtualMachines/{{vmName}}?api-version=2022-08-01
  2. Paste the above URL with the same subscription id, provide the resource group name in which the machine is created and the VM name in the Postman and use the DELETE
  3. Go To Headers and provide the below data as key and value pair.

Content-Type: application/json

Authorization: Bearer <Generate another token>

  1. The API will get processed with code 202 saying Accepted and the machine will be deleted in some time and reflected in the Azure Portal too.

step4svm

Conclusion

From this blog, we can perform operations on Virtual Machines like Creating, Listing (By Resource Group and Subscription ID), Deallocating, and Deleting using the REST API from the POSTMAN Application.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

FAQs

1. Can we perform the same operation on other resources?

ANS: – Yes, we can do the same for all other resources in Azure and API will be different with its related service.

2. Can we fetch other resource details of a created virtual machine like on Disks and Snapshots?

ANS: – Yes, we can fetch those details also using their REST API only.

WRITTEN BY Sridhar Andavarapu

Sridhar Andavarapu is a Senior Research Associate at CloudThat, specializing in AWS, Python, SQL, data analytics, and Generative AI. With extensive experience in building scalable data pipelines, interactive dashboards, and AI-driven analytics solutions, he helps businesses transform complex datasets into actionable insights. Passionate about emerging technologies, Sridhar actively researches and shares insights on AI, cloud analytics, and business intelligence. Through his work, he aims to bridge the gap between data and strategy, helping enterprises unlock the full potential of their analytics infrastructure.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!