Is there a way to get Azure Subscription ID programmatically? - azure

We would like to create some Azure resources using Azure Rest APIs through a C# program. We are able to get access token by following the below msdn doc
https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code .
But the Azure Rest APIs also requires Subscription ID which we are not able to get. Is there a way we can get it through program?
Thanks
Balaji

You can use the below request URI to get list of subscriptions for a tenant. https://management.azure.com/subscriptions?api-version=2016-06-01
Please refer to Get Subscription List for more information.

Related

How to pull Azure Cognitive Search Quota and usage?

I am trying to pull azure cognitive search current and quota .
Can anyone help me on:
" how can I get that information to csv using some service principle."
I found one link to pull this kind of data :
https://learn.microsoft.com/en-us/rest/api/searchservice/get-service-statistics
But I am not sure how to use this api to get above screenshot information.
The link you posted is the correct way to do it, it returns all the information you need.
It looks like this endpoint does not support OAuth2 & RBAC. So instead of using service principal, you need to provide the admin api-key in the request header.
You can check here how to access the api-key. If you'll be doing that from a powershell script, you can authenticate with your service principal and fetch the key using Get-AzSearchAdminKeyPair, then use this key to make a http request to get the statistics and finally convert them to CSV format.

How to get AD user for Azure subscription Classic Administrators?

My goal is to get the Azure AD users who have been assigned the Classic Administrator role in an azure subscription.
I use the REST api's Classic Administrators - List to retrieve all classic admins but it returns an Email which is not unique enough and an ID called netId/puid which is not present on the user returned from the Graph API.
I followed the Azure Portal's network to see how it gets the users for AAD but it queries the Graph API with an internal API version '1.61-internal' that I can't use.
Does anyone know on a way to retrieve this information?
Thanks
There is not an exposed API to match netId/puid with users.
But you can get the puid from the access token.
Or you could use Microsoft 365 Powershell cmdlet Get-MsolUser -UserPrincipalName "{upn}" | fl to get the user and find the LiveId property.
Record the puid or LiveId above and the corresponding user information to your local configuration file and match them with the name property in response of Classic Administrators - List.
Then you can get the corresponding users who are classic Administrators.
It's just a workaround and there are many workloads. I don't think it is a good method but there is no other way.

Is there an API to get the Azure subscription info

I created a web app that use microsoft account to login,then it wil perform a series of Azure related operations on behalf of the web app user automally .
The doc of Azure API and Graph API give many clear examples to control Azure,But I noticed that most operations require a Azure subscription ID , i can get subscription ID on the portal of auzre , but can't find the method to get it by the api .This will make my web app's user need to get subscription ID on the azure portal to the next step ,it make user feel upset.
I try to find the method in doc of Azure API and Graph API. However,
in the doc of Graph API ,I only find the doc about the subcription of microsoft account's event (https://learn.microsoft.com/en-us/graph/api/subscription-list?view=graph-rest-1.0&tabs=http) ;
In the doc of Azure API, I only find the doc about the operation of subscription (https://learn.microsoft.com/en-us/rest/api/subscription/2018-03-01-preview/subscriptionoperations/list)
I couldn't find the api to get current user's subcription info , Is there an API to get the Azure subscription info or just i didn't find it
Just use the API below to get Azure subscription IDs:
Request URL:
GET https://management.azure.com/subscriptions?api-version=2019-06-01
Request Header:
Authorization: Bearer <access token>
Result:
You need to access Azure's management Apis, for example,
To list the subscriptions you can use this endpoint:
"GET management.azure.com/subscriptions{subscriptionId}?api-version=2020-01-01"
and to get information about a specific subscription you can use this endpoint
"GET management.azure.com/subscriptions?api-version=2020-01-01"

Not able to fetch subscription details

I have a multi tenant azure application. When i am trying to fetch subscription details using azure management api, it is always giving null.
I have followed all the steps except step3 mentioned in this post
Fetching VM details from multiple tenants
Its seems that you are trying to get azure subscription Information.
Try with REST API:
GET https://management.azure.com/subscriptions
Note: Refer to this docs. Then click on Try it section.
See the screen shot:
Click on Try it. you will prompt to login login with your credential. After that you will be given option for which tenant you want to get subscription. In response you would get your information like below:

Azure REST API for Azure AD settings

I need to get information about the already configured User Settings from Azure AD through API.
I'm looking for the request with information about "Guests can invite" is set to "No" or "Members can Invite" is set to "No"
Could you please provide me information about the required API call for my purpose?
You can use Azure Powershell to achieve this:
https://learn.microsoft.com/en-us/azure/active-directory/b2b/delegate-invitations#assign-the-guest-inviter-role-to-a-user
Unfortunately it is not possible as of yet to make direct Microsoft Graph calls to add app role assignments. Please follow the GitHub issue : https://github.com/microsoftgraph/microsoft-graph-docs/issues/4155 for an official response.
It is possible to add a new directory role to a user via the AddDirectoryRole API : https://learn.microsoft.com/en-us/graph/api/directoryrole-post-members?view=graph-rest-1.0&tabs=javascript
Hope this helps!

Resources