java - Authorization failed while wget azure REST API -


i trying collect azure metrics using rest api. have free subscription azure account.

i using following wget json message.

wget https://management.azure.com/subscriptions/xxxxxxx/resourcegroups/rg_south_india/providers/microsoft.compute/virtualmachinescalesets/linuxscal/metrics?api-version=2014-04-01 

xxxxxxx- subscription id.

i following error message.

resolving management.azure.com... 13.67.231.219 connecting management.azure.com|13.67.231.219|:443... connected. http request sent, awaiting response... 401 unauthorized authorization failed. 

what wrong subscription/authorization?!!

thanks in advance guys!! stuck!!

you need include authorization header bearer token in call:

get /subscriptions?api-version=2015-01-01 http/1.1 host: management.azure.com authorization: bearer your_access_token content-type: application/json 

take @ armclient, since really don't want this hand (or curl): https://www.npmjs.com/package/armclient

// es6 import armclient, { clientcredentials } 'armclient';  const client = armclient({    subscriptionid: '111111-2222-3333333',   auth: clientcredentials({     tenantid: '444444-555555-666666666',     clientid: '777777-888888-999999999',     clientsecret: 'aaaabbbbbccccc' // or serviceprincipalpassword   }) }); 

your /metrics call becomes:

client.get('/resourcegroups/rg_south_india/providers/microsoft.compute/virtualmachinescalesets/linuxscal/metrics', { 'api-version': '2014-04-01' })   .then((res) => {     console.log(res.body);     console.log(res.headers);   })   .catch((err) => {     console.log(err);   }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -