0

I have a Java Application running on Tomcat. I want to get the details of all machines installed in Microsoft Azure portal by taking user's subscription details as input. Preferably a REST API. I am expecting response same like what we get in azure resource explorer. I made a request with this url "https://management.core.windows.net/"+subscriptionId+"/services/disks" following this method. It gives me result like this

<Disks xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <Disk>
     <AttachedTo>
       <DeploymentName>TEST1</DeploymentName> 
       <HostedServiceName>TEST1</HostedServiceName>
       <RoleName>TEST1</RoleName>
       </AttachedTo><OS>Linux</OS>
       <Location>South Central US</Location>
       <LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>   
       <MediaLink>link.vhd</MediaLink>
       <Name>TEST1-TEST1-0-20</Name>
       <SourceImageName>imageName</SourceImageName>

When I call the same method with

"https://management.azure.com/subscriptions/"+subscriptionid+"/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30" I am getting 401 error.

I even tried downloading the SDK , ListVirtualMachines.java is listing some 600 images, not the one under my subscription.

How Can I achieve it using JAVA REST API?

1 Answer 1

1

Per my experience, this issue is due to the authentication method. I do all the requests that you have made and I get the same results with you. The 401 error code means "Unauthorized". Your authentication method is right for the old REST API request, but not for new.
The new authentication is handled by Azure Active Directory(AD).

The followings may be useful for you.

  1. You could figure out Virtual Machines Rest API by this URL https://msdn.microsoft.com/en-us/library/mt163647.aspx.
  2. You could understand how to authenticate Azure Resource Manager Request by Azure Active Directory by this URL https://msdn.microsoft.com/en-us/library/dn790557.aspx.

Hope it helps. Any concerns, please feel free to let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.