sercanD
sercanD

Reputation: 197

Is there anyway to get subscriptions by Azure API?

Here is my token Authentication

var context = new AuthenticationContext(string.Format(ConfigurationManager.AppSettings["login"], ConfigurationManager.AppSettings["tenantId"]));

var credential = new ClientCredential(ConfigurationManager.AppSettings["clientId"], ConfigurationManager.AppSettings["clientSecret"]);

_token = await context.AcquireTokenAsync(ConfigurationManager.AppSettings["apiEndpoint"], credential);

And yes I got the token now from https://management.core.windows.net/

After that I am creating a new instance of SubscriptionClient under Microsoft.Azure.Management.ResourceManager namespace there is 2 different namespace for this but that is the one I am using.

Here is my instance

_credentials = new TokenCredentials(_managementToken.AccessToken);

_subscriptionClient = new SubscriptionClient(_credentials);

And the finally here is the call

await _subscriptionClient.Subscriptions.ListAsync();

And returns nothing from that.

But from this call

await _subscriptionClient.Tenants.ListAsync();

this returns my tenant id.

BTW I am using WEB APP not a NATIVE APP.

Is there any solution for that. How can I get subscriptions from Management API.

Thanks

Upvotes: 0

Views: 134

Answers (1)

Nan Yu
Nan Yu

Reputation: 27528

Please firstly ensure your subscription has associated with your azure ad tenant :

  1. In classic portal , click Settings menu in the left panel .
  2. You could view the subscription information and the directory it associated with : enter image description here

Please ensure the azure ad tenant you are using has any subscription .

Upvotes: 1

Related Questions