7

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.

shristi
  • 109
  • 1
  • 1
  • 6
  • 1
    Does this answer your question? [Azure Management REST API - "Authentication failed. The 'Authorization' header is provided in an invalid format."](https://stackoverflow.com/questions/39822874/azure-management-rest-api-authentication-failed-the-authorization-header-i) – dropoutcoder Jan 03 '20 at 10:10

4 Answers4

3

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" }
GeralexGR
  • 2,973
  • 6
  • 24
  • 33
2

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

Indar
  • 267
  • 2
  • 11
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

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
1

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)