Code Monkey home page Code Monkey logo

Comments (12)

amarzavery avatar amarzavery commented on August 16, 2024

AFAIK,
This is the only API and it lists tenants. It only provides the tenantId and does not provide the name of the tenant.

@vivsriaus @ravbhatnagar - Is there an API that can provide more info about tenants a GET on
https://management.azure.com/tenants/{tenantId} => Tenants_Get

from azure-sdk-for-js.

vivsriaus avatar vivsriaus commented on August 16, 2024

ARM's /tenants API will list more information about a tenant (including the display name and domain) if you use api-version 2017-08-01:

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/tenants?api-version=2017-08-01

(redacted)
{
"id": "/tenants/f102019f-b12d-446e-a653-71ef78828f59",
"tenantId": "f102019f-b12d-446e-a653-71ef78828f59",
"countryCode": "US",
"displayName": "vivektest",
"domains": [
"vivektest.onmicrosoft.com"
]
}

Issue to update api-version is here

from azure-sdk-for-js.

MichaelBurgess avatar MichaelBurgess commented on August 16, 2024

Thanks for the response - until the referenced issue is fixed, can I set the API version manually for now via the SDK call to tenants.list?

from azure-sdk-for-js.

amarzavery avatar amarzavery commented on August 16, 2024

Nope that wont work. Because the SDK is wired to deserialize the response based on the predefined api-version.
However, we have something wonderful to unblock you. Every client has a generic sendRequest() method that accepts a callback or returns a promise. Since the client already has the credentials object so authentication is not a problem. You can make any request to Azure.

Ideally you would be doing

let client = new ResourceManager.SubscriptionClient(creds);
client.tenants.list((err, result) => {
  . . .  // but this one only resturns an array of id and tenantId
});

So based on the above information provided by @vivsriaus about the REST API, you can use the generic sendRequest() method that is present on every client, until an sdk is published with that api-version (2017-08-01).

  • Promise based
const ResourceManager = require('azure-arm-resource');
const msRestAzure = require('ms-rest-azure');

msRestAzure.interactiveLogin().then((creds) => {
  let client = new ResourceManager.SubscriptionClient(creds);
  const request = {
    url: 'https://management.azure.com/tenants?api-version=2017-08-01',
    method: 'GET'
  };
  return client.sendRequest(request);
}).then((result) => {
  // The response body as a json object;
  console.log(result);
}).catch((err) => {
  console.log(err);
});
  • Callback based
const ResourceManager = require('azure-arm-resource');
const msRestAzure = require('ms-rest-azure');

msRestAzure.interactiveLogin((err, creds) => {
  if (err) {
    return console.log(err);
  }
  let client = new ResourceManager.SubscriptionClient(creds);
  const request = {
    url: 'https://management.azure.com/tenants?api-version=2017-08-01',
    method: 'GET'
  };
  return client.sendRequest(request, (err, result, request, response) => {
    if (err) {
      return console.log(err);
    }
    // The parsed response body
    console.log(result);
  });
});

Documentation for sendRequest(), in case you need it in the future.

from azure-sdk-for-js.

MichaelBurgess avatar MichaelBurgess commented on August 16, 2024

Thanks for the tip on sendRequest, useful to know thanks!

I've tried the sample above and I'm still only getting back a response with the original info:

{
  value: [
    {
      id: '/tenants/<tenantId>',
      tenantId: '<tenantId>'
    }
  ]
}

Is there anything else I can check or let you know to help diagnose?

Thanks.

from azure-sdk-for-js.

MichaelBurgess avatar MichaelBurgess commented on August 16, 2024

FYI, we're using CoffeeScript - here's the code that produces the above:

exports.getTenants = (creds, callback) ->
  client = new resourceManager.SubscriptionClient creds
  request =
    url: 'https://management.azure.com/tenants?api-version=2017-08-01'
    method: 'GET'
  client.sendRequest request, (err, result, request, response) ->
    if err then return callback err
    callback null, result

from azure-sdk-for-js.

amarzavery avatar amarzavery commented on August 16, 2024

Do check the actual request and response (3rd and 4th parameter in the callback) to make sure that everything is as expected.

Well I just ran the following script and everything worked as expected.

const ResourceManager = require('azure-arm-resource');
const msrestazure = require('ms-rest-azure');

msrestazure.loginWithServicePrincipalSecret('clientId', 'secret', 'tenantId', (err, creds) => {
  if (err) return console.log(err);
  const client = new ResourceManager.SubscriptionClient(creds);
  client.sendRequest({
    url: 'https://management.azure.com/tenants?api-version=2017-08-01',
    method: 'GET'
  }, (err, result, request, response) => {
    if (err) {
      console.log(err);
      return;
    }
    console.dir(result, {depth: null});
  });
});

The result is:

{ value:
   [ { id: '/tenants/000000-9089-7676-abc8-ababa121234',
       tenantId: '000000-9089-7676-abc8-ababa121234',
       countryCode: 'US',
       displayName: 'MyTenant',
       domains: [ 'azTest.com', 'azTest.onmicrosoft.com' ] } ] }

from azure-sdk-for-js.

MichaelBurgess avatar MichaelBurgess commented on August 16, 2024

Weirdly, I can only get the same response back as using the tenants.list function. I cleared my node_modules, fresh npm install (we're using 2.2.1-preview of the SDK) and still no joy.

The request and response look fine and the response body is the same as the parsed result.

from azure-sdk-for-js.

amarzavery avatar amarzavery commented on August 16, 2024

@vivsriaus is this API version deployed in all the regions? Can it be possible if the api version is not deployed then it falls back to the old version?

@MichaelBurgess can you provide us the raw request (strip out authentication header)

from azure-sdk-for-js.

MichaelBurgess avatar MichaelBurgess commented on August 16, 2024

FYI, I am making the request from the UK. Don't know if that has any impact on things?

{
  rawResponse: false,
  queryString: {},
  url: 'https://management.azure.com/tenants?api-version=2017-08-01',
  method: 'GET',
  headers:
  {
    'accept-language': 'en-US',
    'x-ms-client-request-id': '62a90ad4-daab-4022-b3be-95b03df30273',
    'Content-Type': 'application/json; charset=utf-8',
    'user-agent': 'Node/v6.11.5 (x64-Linux-4.4.0-98-generic) ms-rest/2.2.5 ms-rest-azure/2.4.4 azure-arm-resource/3.0.0-preview Azure-SDK-For-Node'
  },
  body: null
}

from azure-sdk-for-js.

omarsourour avatar omarsourour commented on August 16, 2024

Is there an API exposed in the SDK to get the tenants for an account?

Also, is there an API exposed in the SDK to get the subscriptions for a tenant?

from azure-sdk-for-js.

Petermarcu avatar Petermarcu commented on August 16, 2024

@omarsourour please open a new issue to track follow up questions.

I'm closing this issue now because the version relevant to the initial report should have been rolled out to all regions by now and the client updated.

from azure-sdk-for-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.