"UnsupportedApiVersion" error when requesting a token in linux function app but working OK on windows

Gonzalez Chiu, Axel 1 Reputation point
2020-06-24T17:28:16.107+00:00

Hi, I've been going through
https://learn.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=powershell
trying to generate an access token for a function app, it seems to be working OK when working with a powershell app, however when doing the same request from a NodeJS app I keep getting back the following error

      "message": "400 - \"{\\\"error\\\":{\\\"code\\\":\\\"UnsupportedApiVersion\\\",\\\"message\\\":\\\"The HTTP resource that matches the request URI 'http://localhost:8081/msi/token/?resource=https://database.windows.net/&api-version=2019-08-01' does not support the API version '2019-08-01'.\\\",\\\"innerError\\\":null}}\"",  

I've tried using different API versions with no success, the documentation specifies to use 2019-08-01 but the service says it's not supported

this is the code I'm currently using to try and request said token

async function getToken() {  
  const resource = "https://database.windows.net/";  
  const options = {  
    method: "GET",  
    uri: `${process.env["IDENTITY_ENDPOINT"]}/?resource=${resource}&api-version=2019-08-01`,  
    headers: {  
      "X-IDENTITY-HEADER": process.env["IDENTITY_HEADER"],  
    },  
  };  
  try {  
    const response = await rp(options);  
    return Promise.resolve(response);  
  } catch (error) {  
    return Promise.resolve(error);  
    // return Promise.reject(error);  
  }  
}  

any insights into what could be happening here are greatly appreciated

edit:
As an update, it seems to be working OK if I set my node js app on a windows server as well but getting the unsupported API version for a node js app on linux which is what I'm trying to actually work with.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,605 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,448 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Mike Urnun 9,786 Reputation points Microsoft Employee
    2020-06-25T00:04:48.77+00:00

    Hello @GonzalezChiuAxel-8194

    There is an open issue under the documentation that calls out the same problem which appears to be resolved by using 2018-11-30 for the API-version: https://github.com/MicrosoftDocs/azure-docs/issues/53726

    Could you try it out and see if it fixes the issue?

    0 comments No comments

  2. Gonzalez Chiu, Axel 1 Reputation point
    2020-06-25T15:13:47.853+00:00

    Hi @MikeUrnun , thanks for the reply; it does still give me the same error while using that API version though.

       "error": "{\"error\":{\"code\":\"UnsupportedApiVersion\",\"message\":\"The HTTP resource that matches the request URI 'http://localhost:8081/msi/token/?resource=https://database.windows.net/&api-version=2018-11-30' does not support the API version '2018-11-30'.\",\"innerError\":null}}",
    
    0 comments No comments

  3. dhiren ghelani 1 Reputation point
    2021-01-07T09:38:00.087+00:00

    the same github issue has a thread that reports to use 2017-09-01. can you try that?

    0 comments No comments