2

I am looking for something similar to this but using JAVA rest API calls. I want to get the list of all the resources (including virtual machines, storage disks, network devices etc) and their basic properties(like ip address, disk space etc) I have tried making API calls following this link.

When I make an http request to this url

"https://management.azure.com/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Compute/virtualMachines?api-version="+apiVersion

But I am getting a 401 error. Am I calling the right URL ? if not which URL I should be calling ?

Community
  • 1
  • 1
Jerry
  • 987
  • 4
  • 16
  • 46

1 Answers1

2

But I am getting a 401 error. Am I calling the right URL ? if not which URL I should be calling ?

You're calling the right URL however you're providing incorrect parameters to the API call. The link you mentioned is for making Azure Service Management API calls however what you need to dod is make Azure Resource Manager (ARM) API calls.

Like Azure Service Management API, ARM API requests need to be authenticated. In case of former, the requests are authenticated by using a management certificate. In case of latter, you would need to use a token that you get by authenticating the user against an Azure AD.

Please see this link for more details on authenticating/authorizing ARM API requests: https://azure.microsoft.com/en-us/documentation/articles/resource-manager-api-authentication/.

In order to list all resources in a resource group, you can definitely make use of ARM REST API. However now SDKs are available for you that you can consume directly. To learn more about these SDKs, please see this link: https://azure.microsoft.com/en-in/blog/azure-resource-manager-preview-sdks/.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • I have added the sdk as new project in eclipse. Did the authentication using AD in azure portal. Now when I run ListVirtualMachineImages.java I am getting more than 500 items, but I have only one virtual machine. Which file I should be running to get the details of my assets? – Jerry Aug 25 '16 at 12:27
  • I would suggest asking a brand new question. Please include your code and the output you're seeing. – Gaurav Mantri Aug 25 '16 at 12:31
  • If I am making a rest api call with the above mentioned url what all parameters I should be passing? – Jerry Aug 25 '16 at 12:46
  • 1
    Can you please tell me how to create the token? – Jerry Aug 27 '16 at 06:54
  • Can somebody tell me how to create token to pass from Postman or from java code? – Sandy Dec 09 '18 at 17:42