• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
FusionAuth
  • Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login

Is there a way to limit number of users for a tenant/application?

Scheduled Pinned Locked Moved Unsolved
Q&A
2
2
1.0k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    maysilees
    last edited by 10 Dec 2023, 22:44

    We are looking to limit the number of users that can be created for a tenant/application - from what I can tell, there isn't a way to do this but I may have missed something. Could webhooks be used to do this perhaps?

    A 1 Reply Last reply 11 Dec 2023, 21:59 Reply Quote 0
    • A
      Alex Patterson @maysilees
      last edited by 11 Dec 2023, 21:59

      @maysilees I don't believe we have a setting for this but you could add your own lambda, which you would then have to do an API call to check for the number of users.

      https://fusionauth.io/docs/extend/code/lambdas/

      https://fusionauth.io/docs/extend/code/lambdas/self-service-registration#self-service-registration-validation-lambda

      To check the number of users in a specific tenant using the FusionAuth API, you can use the "Search for Users" API endpoint. This endpoint allows you to search for users within a tenant and can be used to count the number of users. You would need to set the tenantId in the search criteria to scope the search to a specific tenant.
      Here is an example of how you might use the API to search for all users within a tenant and count them:

      FusionAuthClient client = new FusionAuthClient("your-api-key", "http://localhost:9011");
      ClientResponse<UserSearchResponse, Errors> response = client.searchUsersByQueryString("tenantId:your-tenant-id");
      
      if (response.wasSuccessful()) {
        // The total number of users in the tenant can be retrieved from the total field in the response
        int totalUsersInTenant = response.successResponse.total;
        System.out.println("Total users in tenant: " + totalUsersInTenant);
      } else {
        // Handle error response
      }
      

      Please replace your-api-key with your actual API key and your-tenant-id with the ID of the tenant you want to search. The searchUsersByQueryString method is used to perform the search, and the total field in the successful response will give you the count of users in the specified tenant.
      Note that the above code is a conceptual example based on the information provided in the extracts. The actual implementation may vary depending on the version of the FusionAuth client library you are using and the specific details of your application.
      For more details on the "Search for Users" API, you can refer to the FusionAuth API documentation, which would typically be found at the following link: Search for Users API. However, please note that this link was not provided in the extracts, so you should consult the official FusionAuth documentation for the most accurate and up-to-date information.

      1 Reply Last reply Reply Quote 0
      1 out of 2
      • First post
        1/2
        Last post