# Querying entities for all user created DBs

**URL:** <https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061>\
**Category:** API & Programming\
**Created:** [April 8, 2024, 12:30pm UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061 "2024-04-08T12:30:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 8, 2024, 12:30pm UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/1 "2024-04-08T12:30:55Z")

</div>

I would like to query all entities in my fibery account dynamically (without providing the DB names, but rather extracting them from the schema). For this, I need to understand from the schema which types are user generated DBs and which types are internal/ system types.

I noticed there are many metadata flags returned, some of them are:

- “fibery/domain?”
- “fibery/platform?”
- “fibery/secured?”
- “fibery/entity-component?”
- “fibery/schema-only?”
- “fibery/type-component?”
- “fibery/enum?”

Is it possible to have a quick description of what each of these fields mean?  
Also is there is any recommendation on how to “understand” from the schema which types are user generated DBs?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 8, 2024, 12:50pm UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/2 "2024-04-08T12:50:23Z")

</div>

If you filter on `fibery/domain? == true` then you will get all the databases in your spaces (+ the user db).

Out of interest, what is your end goal with querying all the entities?

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 9, 2024, 12:46pm UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/3 "2024-04-09T12:46:10Z")

</div>

Thank you for the prompt response!

We are creating an integration with Fibery, and want to query all entities generically in our system.

I have some follow up questions:

1. You mentioned using the domain flag leaves you with the user DB as well- if I wanted to filter this without hardcoding the user db name, would you say that filtering on the “platform” flag (fibery/platform? == false && fibery/domain? == true) would be sufficient (to only retrieve the space DBs)?
2. Is there any way to retrieve all the account’s space names, other than traversing the schema and filtering (in order to use with the GraphQL API that requires the space name as part of the URL path)?
3. Is there a way to retrieve full rich text fields content using the REST API entities query (without having to separately GET each rich text field using the document endpoint)? If not - is the only way to retrieve all rich documents content in a single request - to use the GraphQL API?
4. Is there a way to retrieve the total number of entities in a DB (asking both for REST and for GraphQL)?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 9, 2024, 3:10pm UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/4 "2024-04-09T15:10:36Z")

</div>

> [@Inbar\_Assaf](#):
>
> We are creating an integration with Fibery

Sounds interesting, would love to hear more.

> [@Inbar\_Assaf](#):
>
> if I wanted to filter this without hardcoding the user db name, would you say that filtering on the “platform” flag (fibery/platform? == false && fibery/domain? == true) would be sufficient

Well, it would work. But the full typename for the user db `fibery/user` is not expected to change, so there’s no real advantage that I can think of.

> [@Inbar\_Assaf](#):
>
> Is there any way to retrieve all the account’s space names, other than traversing the schema and filtering

Spaces are known as apps in the API terminology, and are in fact ‘entities’ of the type ‘fibery/app’, so this will work:

```auto

 "command": "fibery.entity/query",
    "args": {
        "query": {
            "q/from": "fibery/app",
            "q/select": ["fibery/name"],
            "q/where": ["=", ["fibery/show-in-menu?"], true],
            "q/limit": "q/no-limit"
        }
    }

```

> [@Inbar\_Assaf](#):
>
> Is there a way to retrieve full rich text fields content using the REST API entities query (without having to separately GET each rich text field using the document endpoint)?

Have a look here:  
[https://the.fibery.io/@public/User\_Guide/Guide/Entity-API-264/anchor=Select-rich-text-Field--f9838a54-3d74-4f49-9f5d-9195731c7e89](https://the.fibery.io/@public/User_Guide/Guide/Entity-API-264/anchor=Select-rich-text-Field--f9838a54-3d74-4f49-9f5d-9195731c7e89)

specifically this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/6/60fe029ba8251fe1cdcc870c365d21c343185959.png)

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 10, 2024, 8:27am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/5 "2024-04-10T08:27:50Z")

</div>

Thank you so much, this is great info and very helpful!

2 more questions if that’s ok

1. Is there a way to retrieve the total number of entities in a DB (asking both for REST and for GraphQL)?
2. When trying to query graphQL for a space that has no DBs, I get a 500 error response with the following message: “There are no any databases for space [Getting Started]”. Introspection fails on this error. Is this a bug or the intended behaviour?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 10, 2024, 8:39am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/6 "2024-04-10T08:39:44Z")

</div>

> [@Inbar\_Assaf](#):
>
> When trying to query graphQL for a space that has no DBs

What is the nature of the query? I mean, why would you want to query a space that has no DBs?

> [@Inbar\_Assaf](#):
>
> Is there a way to retrieve the total number of entities in a DB (asking both for REST and for GraphQL)?

I don’t believe it is possible, except by performing an unfiltered query and calculating the size of the returned array of entities.  
What is the underlying need to know how many entities there are?

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 10, 2024, 9:58am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/7 "2024-04-10T09:58:40Z")

</div>

Our use case is roughly as follows:  
We want to periodically query all user spaces for new entities (using GraphQL as it seems to fit our needs best), without assuming any prior knowledge of what spaces/ dbs exist.  
When fetching all user spaces using your suggestion (using the entities query from apps), we also receive spaces that have no DBs (if they exist in the account).  
Is there a way to know from metadata that a space has no DBs (so we can skip querying it)?

As for knowing the total number of entities- we’d like to track a percentage progress of our queries.

Thanks again, appreciate all the help!

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 10, 2024, 10:21am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/8 "2024-04-10T10:21:56Z")

</div>

> [@Inbar\_Assaf](#):
>
> When fetching all user spaces using your suggestion (using the entities query from apps), we also receive spaces that have no DBs (if they exist in the account).  
> Is there a way to know from metadata that a space has no DBs (so we can skip querying it)?

If you want to query all dbs, then there is no need to query all spaces, is there? Just check for domain dbs and query them directly.

> [@Inbar\_Assaf](#):
>
> We want to periodically query all user spaces for new entities (using GraphQL as it seems to fit our needs best), without assuming any prior knowledge of what spaces/ dbs exist.

Sounds intriguing. Where is the data ending up?  
If you can’t make assumptions ahead of time about the schema, I’m curious to know what the downstream activities might be.

> [@Inbar\_Assaf](#):
>
> As for knowing the total number of entities- we’d like to track a percentage progress of our queries.

Is this because you are keeping track of the total number of entities in a db, and then using this number to decide if new entities have been added?

Overall, it does sound like you might be better served by using [webhooks](https://the.fibery.io/@public/User_Guide/Guide/Webhooks-258), to get notified of changes, and then update/maintain your webhooks as needed if the Fibery schema changes.

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 10, 2024, 10:27am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/9 "2024-04-10T10:27:08Z")

</div>

> [@Chr1sG](#):
>
> If you want to query all dbs, then there is no need to query all spaces, is there? Just check for domain dbs and query them directly.

Can you suggest how to do that using GraphQL? Each space has its own graphQL endpoint, and to construct a graphQL query, introspection needs to be available- but it fails for spaces without DBs.

> [@Chr1sG](#):
>
> Sounds intriguing. Where is the data ending up?  
> If you can’t make assumptions ahead of time about the schema, I’m curious to know what the downstream activities might be.

I’d be happy to elaborate in PM.

We have looked at webhooks as an option, but it does not answer our requirements.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 10, 2024, 10:31am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/10 "2024-04-10T10:31:09Z")

</div>

> [@Inbar\_Assaf](#):
>
> Can you suggest how to do that using GraphQL?

Why use GraphQL? The REST API is better for this sort of thing.

> [@Inbar\_Assaf](#):
>
> I’d be happy to elaborate in PM.

Feel free to message me here.

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 10, 2024, 10:40am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/11 "2024-04-10T10:40:16Z")

</div>

> [@Chr1sG](#):
>
> Why use GraphQL? The REST API is better for this sort of thing.

Because of the issue I mentioned with fetching rich text fields as part of the same query. If I were to use REST API- I would need to parse the response, take all the document secrets, and query for those using the endpoint you mentioned, making the solution more complex than GraphQL which returns rich text fields as part of the same query.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 10, 2024, 10:52am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/12 "2024-04-10T10:52:19Z")

</div>

> [@Inbar\_Assaf](#):
>
> Because of the issue I mentioned with fetching rich text fields as part of the same query. If I were to use REST API- I would need to parse the response, take all the document secrets, and query for those using the endpoint you mentioned, making the solution more complex than GraphQL which returns rich text fields as part of the same query.

I meant that you could use the REST API to get the complete list of Databases (including which Space they belong to) and then use this info in any way you like (including GraphQL queries to get the entities)

---

<div class="post-metadata">

**Author:** ![Inbar\_Assaf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/inbar_assaf/32/9161_2.png) [@Inbar\_Assaf](https://community.fibery.io/u/Inbar_Assaf)\
**Post date:** [April 10, 2024, 10:55am UTC](https://community.fibery.io/t/querying-entities-for-all-user-created-dbs/6061/13 "2024-04-10T10:55:10Z")

</div>

> [@Chr1sG](#):
>
> I meant that you could use the REST API to get the complete list of Databases (including which Space they belong to) and then use this info in any way you like (including GraphQL queries to get the entities)

I see, thank you. This is what I initially did and it does work well, but the suggestion you had here:

> [@Chr1sG](#):
>
> Spaces are known as apps in the API terminology, and are in fact ‘entities’ of the type ‘fibery/app’, so this will work:

Is much cleaner and easier to maintain, but I understand that it is less appropriate for my use case. Thank you!
