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

Retrieving Data using FusionAuth API

Scheduled Pinned Locked Moved
Q&A
4
15
11.5k
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.
  • H
    humaira.tum11
    last edited by 7 Jul 2020, 15:45

    Hello everyone,

    Can someone please highlight which API functions/calls will be used to retrieve following Data

    • Retrieving List of all users for a specific tenant
    • Retrieving List of all users within a specific application for a particular tenant
    • Retrieving tenant ID of a user based on its email ID/username only.
    • Retrieving List of Tenants present in FusionAuth server
    • Retrieving List of Applications associated with a specific tenant.
    • Retrieving List of all the applications in FusionAuth server.

    Thank you
    Humaira

    1 Reply Last reply Reply Quote 1
    • D
      dan
      last edited by 7 Jul 2020, 16:56

      Hiya,

      The API documentation will have answers for most of these. https://fusionauth.io/docs/v1/tech/apis/

      --
      FusionAuth - Auth for devs, built by devs.
      https://fusionauth.io

      H 1 Reply Last reply 8 Jul 2020, 10:03 Reply Quote 0
      • H
        humaira.tum11
        last edited by 8 Jul 2020, 08:23

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • H
          humaira.tum11 @dan
          last edited by 8 Jul 2020, 10:03

          @dan Thank you for the link. I actually did go through the API documentation. But I couldn't find API call for the following highlighted queries:
          a Retrieving List of all users for a specific tenant
          b Retrieving List of all users within a specific application for a particular tenant

          • Retrieving List of all users for a specific tenant
            bad4dbf6-9044-496b-a4c9-52c3c25d4357-image.png
            In here, "Retrieve a user" only retrieves a single user.
            "Search for Users", it also only retrieves the users whose Ids are provided in the query.
            its the same for following, I can't find any API calls in API documentation of Users, Registration, Login or Tenants/Application.
            • Retrieving List of all users within a specific application for a particular tenant

          I have created a generic group as well, and then try to add users into that. When I retrieve the group i don't get any information regarding they are part of which groups. So It can not be used as well.

          Q1 - Is it not possible retrieve these datas?
          Q2 - Do we have to separately keep a database to maintain the list our self to retrieve these data on go.
          (This data is required by us to create a management portal for both super admin who manages all the tenants/applications related information and for individual tenant admins who manages their own users and their related information. )

          Thank you
          Humaira

          1 Reply Last reply Reply Quote 1
          • D
            dan
            last edited by 8 Jul 2020, 15:25

            Hiya,

            If you are using the elasticsearch search engine, you can use the admin UI and then see the elasticsearch string you'd need to set the queryString to in order to run the same search. This is the API which takes the `queryString: https://fusionauth.io/docs/v1/tech/apis/users#search-for-users

            a Retrieving List of all users for a specific tenant

            queryString = tenantId:64c1844b-04ef-4bc8-b4ea-3d8bf2e586e9 (or whatever your tenantId is)

            b Retrieving List of all users within a specific application for a particular tenant

            In this case you need to use a raw JSON query, which will be passed through to elasticsearch:

            {
              "bool" : {
                "must" : [ {
                  "nested" : {
                    "path" : "registrations",
                    "query" : {
                      "bool" : {
                        "must" : [ {
                          "match" : {
                            "registrations.applicationId" : "c6b9de0c-2f71-4019-920b-58bc2d4206fc"
                          }
                        } ]
                      }
                    }
                  }
                }, {
                  "query_string" : {
                    "query" : "tenantId:32306536-3036-6431-3865-646430303332"
                  }
                } ]
              }
            }
            

            (again, set your tenantId and applicationId.)

            Note that you can't use the query JSON if you are using the database search engine. Here's how to switch between them: https://fusionauth.io/docs/v1/tech/tutorials/switch-search-engines

            This data is required by us to create a management portal for both super admin who manages all the tenants/applications related information and for individual tenant admins who manages their own users and their related information.

            You can build your own management portal, for sure. An alternative you may consider is creating FusionAuth users that have access to the FusionAuth application, but with limited permissions. That may or may not work for you, but you may want to evaluate it if you haven't had a chance (there are a number of predefined roles).

            --
            FusionAuth - Auth for devs, built by devs.
            https://fusionauth.io

            S 1 Reply Last reply 15 Jul 2020, 08:30 Reply Quote 0
            • S
              srothery @dan
              last edited by 15 Jul 2020, 08:30

              @dan Hi can I just check then that if I'm using the database search engine there isn't way of obtaining a list of users. We have a simple use case with a small number of users, perhaps only a single application and just a few roles within that. Getting a list of user ids that we could then enumerate for display and other purposes is something we would need to do. We would rather not have to upgrade the search engine to Elastic in order to do this but is this the only way?
              Many thanks for your time,
              Simon

              1 Reply Last reply Reply Quote 1
              • D
                dan
                last edited by 15 Jul 2020, 13:15

                if I'm using the database search engine there isn't way of obtaining a list of users

                You can definitely retrieve all users within the tenant with the database engine, just use a queryString of * and the tenant header. If you only have a few users, applications and tenants, I'd suggest using additional filtering in your application. So I'd retrieve all users for a tenant and then filter by their registrations to get the application associations.

                An alternative would be to file a feature request to enhance the database engine functionality to give you what you need.

                Does this help?

                --
                FusionAuth - Auth for devs, built by devs.
                https://fusionauth.io

                1 Reply Last reply Reply Quote 1
                • S
                  srothery
                  last edited by srothery 15 Jul 2020, 14:51

                  Hi Dan,

                  That is good news indeed. I think I'm just not understanding or misreading the docs https://fusionauth.io/docs/v1/tech/apis/users#search-for-users which seems to be saying use of "query" or "queryString" either only works with ES or only supports a few fields like username, email etc. I will try something like:

                  GET /api/user/search?queryString=*
                  

                  later on today.

                  Many thanks for your time,

                  Simon

                  Edit: it works 🙂 thanks again

                  1 Reply Last reply Reply Quote 1
                  • D
                    dan
                    last edited by 15 Jul 2020, 15:38

                    Great! We have a PR out to revisit the search documentation which I just merged. So hopefully that will be clearer for folks in the future.

                    --
                    FusionAuth - Auth for devs, built by devs.
                    https://fusionauth.io

                    S K 3 Replies Last reply 15 Jul 2020, 16:18 Reply Quote 0
                    • S
                      srothery @dan
                      last edited by 15 Jul 2020, 16:18

                      @dan said in Retrieving Data using FusionAuth API:

                      Great! We have a PR out to revisit the search documentation which I just merged. So hopefully that will be clearer for folks in the future.

                      That sounds great. Out of interest did you mean I could filter on applicationId in the query as well? I've tried:

                      http://{{dockerhost}}:{{fusionport}}/api/user/search?queryString=*&applicationId=85a03867-dccf-4882-adde-1a79aeec50df
                      

                      and

                      http://{{dockerhost}}:{{fusionport}}/api/user/search?queryString=*&registrations.applicationId=85a03867-dccf-4882-adde-1a79aeec50df
                      

                      but doesn't seem to filter the results further.

                      Many thanks for your time,

                      Simon

                      1 Reply Last reply Reply Quote 0
                      • D
                        dan
                        last edited by 15 Jul 2020, 17:12

                        Sorry, you'll need to filter on the application by examining the results of the search api call (which should return all users) in your application code, and filtering it in business logic.

                        You can't do that in the FusionAuth database search (though, again, you can with elasticsearch).

                        --
                        FusionAuth - Auth for devs, built by devs.
                        https://fusionauth.io

                        1 Reply Last reply Reply Quote 0
                        • S
                          srothery
                          last edited by 16 Jul 2020, 07:38

                          Ok - thanks for confirming.

                          1 Reply Last reply Reply Quote 1
                          • K
                            kasir-barati @dan
                            last edited by 17 Nov 2023, 12:41

                            @dan 508a04ee-ef1f-4959-bd08-423490e35807-image.png

                            Still not really clear though but at least this Q&A forum is really resourceful

                            D 1 Reply Last reply 17 Nov 2023, 23:05 Reply Quote 0
                            • D
                              dan @kasir-barati
                              last edited by 17 Nov 2023, 23:05

                              @kasir-barati Can you be more specific about your question?

                              --
                              FusionAuth - Auth for devs, built by devs.
                              https://fusionauth.io

                              1 Reply Last reply Reply Quote 0
                              • K
                                kasir-barati @dan
                                last edited by 22 Nov 2023, 12:05

                                @dan said in Retrieving Data using FusionAuth API:

                                Great! We have a PR out to revisit the search documentation which I just merged. So hopefully that will be clearer for folks in the future.

                                Back to this comment of yours, I meant that the first line in this screenshot kinda confused me, since I thought that you're searchQuery will be searched only for these fields and not all of the existing fields if you call this this endpoint http://{{dockerhost}}:{{fusionport}}/api/user/search?queryString=*

                                And also I did not know that I can do something like http://{{dockerhost}}:{{fusionport}}/api/user/search?queryString=tenantId:uuid

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post