Azure.ResourceManager.ApiManagement

Aml Abbas 40 Reputation points
2024-04-22T11:50:43.3166667+00:00

Hello,

How to use package Azure.ResourceManager.ApiManagement to:

  • Get a list of all users in Azure api management.
  • Create a user in Azure api management.
  • Add the user to a group
  • Create a subscription for the user
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,768 questions
0 comments No comments
{count} votes

Accepted answer
  1. hossein jalilian 2,985 Reputation points
    2024-04-22T19:47:20.6233333+00:00

    Hello Aml Abbas,

    Thanks for posting your question in the Microsoft Q&A forum.

    • Get a list of all users in Azure api management.
        ArmClient armClient = new ArmClient(new DefaultAzureCredential());
        SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
        ApiManagementService apiManagementService = await subscription.GetApiManagementServices().GetAsync("resourceGroupName", "serviceName");
        AsyncPageable<ApiManagementUserResource> users = apiManagementService.GetUsers();
        await foreach (ApiManagementUserResource user in users)
        {
          //code...
        }
      
    • Create a user in Azure api management.
        ApiManagementUserData userData = new ApiManagementUserData
        {
            FirstName = "amal",
            LastName = "abbas",
            Email = "abbas@example.com",
            State = ApiManagementUserState.Active
        };
        ApiManagementUserResource userResource = await apiManagementService.GetUsers().CreateOrUpdateAsync(true, "user-111", userData);
      
    • Add the user to a group
        ApiManagementGroupResource group = await apiManagementService.GetGroups().GetAsync("developers");
        await group.GetUsers().CreateOrUpdateAsync(true, "user-111");
      
    • Create a subscription for the user
        ApiManagementSubscriptionData subscriptionData = new ApiManagementSubscriptionData
        {
            DisplayName = "My Subscription",
            State = ApiManagementSubscriptionState.Active,
            UserId = "/users/user-111"
        };
        ApiManagementSubscriptionResource subscription = await apiManagementService.GetSubscriptions().CreateOrUpdateAsync(true, "my-subscription", subscriptionData);
      

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful


0 additional answers

Sort by: Most helpful