API Azure Browser docs.microsoft.com edge (Chromium based) Try it

’Quick and Dirty’ – ad-hoc ways of GETting data from Azure Management API

Background

Some times there is ad-hoc need to get data from Azure Management API, for example all the public IP’s on a subscription. I use this trick often when I want to have an array of data ready to be consumed on some other service.

https://docs.microsoft.com/en-us/rest/api/virtualnetwork/publicipaddresses/listall

Typically I would use something as NodeJS client with ExpressJS to do also parsing, rendering and even scheduling of such requests, But it requires, that you register the client for the API, and sometimes is too time consuming (unless you have the client ready, and are already using it to multiple other cases) (https://securecloud.blog/2020/04/24/hidden-gem-in-azure-scan-your-docker-images-in-acr-view-results-in-sub-assessment-api-and-azure-security-center/#clientcreds)

Options?

  1. Use the Try It feature (This is true hidden gem)

2.Powershell and Edge (Chromium based) – When what you are looking to do for is not available with the ”Rest API try IT” feature, and want to have larger amount of data available in powershell right from the response

’Copy as PowerShell’ with Edge (Chromium based)

  • If you have Edge, or Chrome, there is neat trick in the toolbox ’

Disclaimer (Use read only account, and don’t copy POST/PUT/PATCH requests, as those are usually done to request change on an Azure Object)

  • Look for an request containing get
  • use the ’Copy as Powershell’ Feature
  • Paste the result to VSCode and change the method to ’Invoke-RestMethod’
  • Modify the URI in the headers to match the docs.microsoft.com example. In my case I replace the original query params and path with ’/providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01’
#original 
https://management.azure.com/subscriptions/6193053b-408b-44d0-b20f-4e29b9b67394?originalStuff&morestuff
#New version
https://management.azure.com/subscriptions/6193053b-408b-44d0-b20f-4e29b9b67394//providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01
  • The resulting script looks like this with the authorization and some other headers removed (works for approx one hour ;))
$rq = Invoke-RestMethod -Uri "https://management.azure.com/subscriptions/6193053b-408b-44d0-b20f-4e29b9b67394/providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01" `
-Headers @{
"x-ms-client-session-id"="a39bca8b8a82475ebf6262f81aac4f78"
  "Authorization"=""
  "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41"
} `
-ContentType "application/json"
$rq.value

This was quick! 🙂

0 comments on “’Quick and Dirty’ – ad-hoc ways of GETting data from Azure Management API

Vastaa

Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

WordPress.com-logo

Olet kommentoimassa WordPress.com -tilin nimissä. Log Out /  Muuta )

Twitter-kuva

Olet kommentoimassa Twitter -tilin nimissä. Log Out /  Muuta )

Facebook-kuva

Olet kommentoimassa Facebook -tilin nimissä. Log Out /  Muuta )

Muodostetaan yhteyttä palveluun %s

%d bloggaajaa tykkää tästä: