'The Authorization header is missing

I am getting this error :{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}} whenever I am trying to test my API that is

https://management.azure.com/subscriptions/{subscriptionID}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus?api-version=2019-03-01

Can anybody suggest a solution how to set authentication header in postman or API Tester.



Solution 1:[1]

Authorization is the part of HTTP Header and generally it is token which is Base64 encoded. In Postman, you can add it by clicking on "Headers" button.

This is where Authorization is set in Postman

Solution 2:[2]

You need to set up and configure Postman to obtain an Azure Active Directory token.

A full walk though is covered here - screen shots below for quick reference.

Getting a token using Postman

From the docs - a sample token request form.

Token request form

Solution 3:[3]

This is a guide to use curl to get the https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127.

You can replace the place holder to your service principal in this command.

curl -vX POST -d "grant_type=client_credentials&client_id=${spClientId}&client_secret=${spSecret}&resource=https%3A%2F%2Fmanagement.azure.com%2F" https://login.microsoftonline.com/${spTenantId}/oauth2/token)

Solution 4:[4]

An easy way to get a Bearer token in order to use for Authentication header would be to use az cli.

$token =  az account get-access-token | ConvertFrom-Json

Then by accessing $token.accesstoken you will have string as shown below.

enter image description here

You can use this Token then with your API call as a Bearer token

$headers = @{ Authorization = "Bearer $token.accesstoken" }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Indar
Solution 2 Murray Foxcroft
Solution 3 Galia Cheng
Solution 4 GeralexGR