Posted on Leave a comment

Authentication failed. The ‘Authorization’ header is missing – Invoke-WebRequest Azure ARM

While building an automation procedure I had to POST the management API of Azure.

Invoke-WebRequest -Uri https://management.azure.com/subscriptions/pool/xxx/xxxx/xxxx/xxxx -Method POST

When I used the Invoke-WebRequest without Authentication it failed. The error that you will get when you do not have Authentication headers set can be found below.

Invoke-WebRequest: {"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}}

In order to authenticate with azure you can get an access-token using az cli.

az account get-access-token

The output will look like the below output:

{
  "accessToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxVG-hTDHECYJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-B5FA9l9RvqOls3iaDDYw5O86acvLIwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-ixxxxxxxxxxxxxxxxx3eoeKlxZfxxxxxxxxxxfGW2O6oA",
  "expiresOn": "2022-05-05 14:51:08.000000",
  "subscription": "a23eef11-f200-4722-866c-248ca45142f6",
  "tenant": "1efa646f-3fc3-4554-bd8c-651879a2b110",
  "tokenType": "Bearer"
}

You should take the output of the token and use it on your call.

For example using POSTMAN you should place your token under the Authorization tab. You will then be able to get the result from Azure ARM api.

Posted on 2 Comments

Update variable group using Azure DevOps rest API – POSTMAN

I was struggling to update a variable group using the Azure DevOps Rest API. In this article I will document the procedure using POSTMAN.

First things first you should create a PAT in order to interact with the API. If you do not know how to create such a thing you should read my previous article about running a build through a REST api on which I documented also the creation of a PAT.

Then you will need to add the access token under authorization tab of POSTMAN using Type Basic Auth. The PAT should be added as plain text.

Then you will need to add Content-Type as application/json under Headers.

Then you will have to create your URL. This should be of the format:

https://dev.azure.com/Organization/project/_apis/distributedtask/variablegroups/groupVariableID?api-version=5.1-preview.1

Important: You should use the version=5.1-preview.1. If you use the latest version you will notice an error on the call. This is a bug that has not been fixed as I found online.

In my example I wanted to update the variable group with the ID 5 and add a variable named new-var. The body of your request should be like below. Keep in mind that we use the PUT HTTP verb to update the variable group. This means everything that is inside the variable group will be discarded. If you followed all the steps correctly you will notice the below output JSON. This should indicate success on the procedure.

Lastly you can locate your new variable inside the variable group.

Variablegroups – Update – REST API (Azure DevOps Task Agent) | Microsoft Docs

Video tutorial on YouTube:

Posted on Leave a comment

Query Azure Easy Tables with Postman

There is an easy way to interact with Easy Tables on Azure when you want to test things.

 

You can use a program like postman and create a post request for your table. For example if your table is named users, you should use users after tables/

http://YOURURL.azurewebsites.net/tables/users

 

 

I was testing some requests and I was dealing an exception and I figured that the request should contain the following things.

In the headers is necessary to add Content-Type and Zumo-Api-Version.

 

 

After that you should easily send your post request by selecting raw in the body section.