# How to get all entities of a database?

**URL:** <https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224>\
**Category:** Ideas & Features\
**Tags:** automations\
**Created:** [February 6, 2025, 8:46am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224 "2025-02-06T08:46:30Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 6, 2025, 8:46am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/1 "2025-02-06T08:46:30Z")

</div>

I have a list of to-be-deleted ids, but using

```js
await deleteEntityBatch(type, ids)

```

doesn’t delete them. To double confirm I want to check whether an id string is in a database or not. I read the documentation and find nothing.

> **[Scripts in Automations](https://the.fibery.io/@public/User_Guide/Guide/Scripts-in-Automations-54)**

---

<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:** [February 6, 2025, 9:19am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/2 "2025-02-06T09:19:20Z")

</div>

Simplest way is probably to use a graphql query.  
[https://the.fibery.io/@public/User\_Guide/Guide/GraphQL-Queries-255](https://the.fibery.io/@public/User_Guide/Guide/GraphQL-Queries-255)

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 6, 2025, 3:23pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/3 "2025-02-06T15:23:43Z")

</div>

just for the sake of learning, what would be other ways?

---

<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:** [February 6, 2025, 4:50pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/4 "2025-02-06T16:50:07Z")

</div>

A normal [API entity query](https://the.fibery.io/@public/User_Guide/Guide/Entity-API-264/anchor=Get-Entities--0a5b17e3-bb53-4ee2-b14a-4e2757e1af9d).

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 1:21am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/5 "2025-02-07T01:21:54Z")

</div>

So I guess there is no way to query that in the automation script? Why is that?

---

<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:** [February 7, 2025, 6:31am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/6 "2025-02-07T06:31:51Z")

</div>

Yeah, sure. It’s possible to make graphql and/or regular API calls from a script.  
Use  
`graphql()`  
or  
`executeSingleCommand()`  
function.

[https://the.fibery.io/@public/User\_Guide/Guide/Scripts-in-Automations-54/anchor=Fibery-service-workspace-functions--86ec1778-15d4-42dc-a533-a57ec38bc855](https://the.fibery.io/@public/User_Guide/Guide/Scripts-in-Automations-54/anchor=Fibery-service-workspace-functions--86ec1778-15d4-42dc-a533-a57ec38bc855)

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 7:34am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/7 "2025-02-07T07:34:20Z")

</div>

```js
const fibery = context.getService("fibery");
const query = '{findKyPhis {id, name}}'
const graphql = await fibery.graphql("Kỳ phí", query)
console.log(graphql)

```

The result:

```auto
Failed to execute Action "Script": Request path contains unescaped characters

```

I’m not sure what path it’s referring to. Trying:

```js
const query = '\{findKyPhis \{id, name\}\}'

```

doesn’t help either.

> [@Chr1sG](#):
>
> It’s possible to make graphql and/or regular API calls from a script.

I mean, why there isn’t a native way to get that in the automation script? It seems to me that it’s better to use webhook instead of automation scripts.

---

<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:** [February 7, 2025, 7:56am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/8 "2025-02-07T07:56:49Z")

</div>

> [@Ooker](#):
>
> I mean, why there isn’t a native way to get that in the automation script?

🤷  
I guess there hasn’t been enough demand for it to warrant spending developer time on it.

But overall, I’m not sure what you’re trying to achieve.  
You wrote

> [@Ooker](#):
>
> I have a list of to-be-deleted ids

but that

> [@Ooker](#):
>
> I want to check whether an id string is in a database

Where did the list of ids to be deleted come from?  
I’m curious how you can already have a list of ids to be deleted but not know whether or not there exist any entities with these ids?

---

<div class="post-metadata">

**Author:** ![mdubakov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/mdubakov/32/10_2.png) [@mdubakov](https://community.fibery.io/u/mdubakov)\
**Post date:** [February 7, 2025, 8:09am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/9 "2025-02-07T08:09:25Z")

</div>

If you need to delete all entities from one database, here is the trick

1. Create new Space and move this database to this Space
2. Click … near new Space name and select Delete all Data
3. Move database back to original Space
4. Delete just created space completely

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 3:39pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/10 "2025-02-07T15:39:09Z")

</div>

> [@Chr1sG](#):
>
> Where did the list of ids to be deleted come from?

If you remember [my previous question](https://community.fibery.io/t/how-to-get-the-list-of-entities-in-an-relation-field/8218), in db A I have a many-to-one relation field with db B. So I get the list of ids of B entities my querying on A:

```js
const bEntities = (await fibery.getEntityById(dbA, aEntityId, ["field"]))["field"]
const ids = bEntities.map(({ Id }) => Id)

```

Any idea on how to fix this code?

> [@Ooker](#):
>
> ```auto
> const fibery = context.getService("fibery");
> const query = '{findKyPhis {id, name}}'
> const graphql = await fibery.graphql("Kỳ phí", query)
> console.log(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:** [February 7, 2025, 3:46pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/11 "2025-02-07T15:46:33Z")

</div>

I can’t immediately see what’s wrong with your code, but I’m wondering what the underlying problem to be solved is, and why you’re choosing to attempt a solution with scripting?

Is it not possible to solve with no-code automation actions?

---

<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:** [February 7, 2025, 3:54pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/12 "2025-02-07T15:54:53Z")

</div>

> [@Chr1sG](#):
>
> I can’t immediately see what’s wrong with your code

Actually, the problem is almost certainly the non-english characters in your space name.

I tried with a space called `"Ky phi"` instead of `"Kỳ phí"` and it worked fine

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 5:21pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/13 "2025-02-07T17:21:42Z")

</div>

> [@Chr1sG](#):
>
> I’m wondering what the underlying problem to be solved is, and why you’re choosing to attempt a solution with scripting?

My problem is to recalculate the intervals of insurance payment. The A database is the contracts. One of its fields is the intervals (monthly, quarterly, semi-annually, annually), and another one is a relation field to B. The B database contains all the payment periods. (This is what “Kỳ phí” means). When I change the interval of a contract, outdated periods from previous calculation are deleted and updated periods are created.

The calculation is complex enough that no-code automation action can handle. So far I have written around 300 lines of code, not to mention test cases and bundle scripts.

> [@Chr1sG](#):
>
> Actually, the problem is almost certainly the non-english characters in your space name.

I understand it now. However replacing the name with `encodeURIComponent("Kỳ phí")` results this new error:

```js
Failed to execute Action "Script": There are no any databases for space [Kỳ phí]

```

---

<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:** [February 7, 2025, 8:21pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/14 "2025-02-07T20:21:45Z")

</div>

I just tested as shown below, and it works fine for me.

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

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 8, 2025, 5:57am UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/15 "2025-02-08T05:57:42Z")

</div>

Ah stupid me. I mistook the space name and the database name

---

<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:** [February 8, 2025, 2:23pm UTC](https://community.fibery.io/t/how-to-get-all-entities-of-a-database/8224/16 "2025-02-08T14:23:48Z")

</div>


