# Firebase Database Action

Use this action to insert, update, delete or retrieve one or more Firebase cloud documents from your Firebase account.

![](/files/-MROhpaZ4GksHUKuFWtN)

### Settings

The action uses the following settings:

| Setting                 | Description                                                                                                                                        | [Parsed](/actions-and-operations/dynamic-parsing.md) |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| Firebase Account JSON   | The JSON account token that you can retrieve from your [Firebase](https://www.xenioo.com/en/using-firebase-cloud-data-with-your-chatbot/) account. | :white\_check\_mark:                                 |
| Action                  | The type of action you want to execute on the database.                                                                                            | :no\_entry:                                          |
| Project Id              | The project id of your database.                                                                                                                   | :white\_check\_mark:                                 |
| Database Name           | The name of your database. If you have only one database, you can leave (default) as name.                                                         | :white\_check\_mark:                                 |
| Collection Name         | The name of the database collection you want to target with your command.                                                                          | :white\_check\_mark:                                 |
| Document Id             | The Id of the document you want to target with your action.                                                                                        | :white\_check\_mark:                                 |
| Document Payload        | The full JSON payload of your document.                                                                                                            | :white\_check\_mark:                                 |
| Structured Query Filter | The full structured query payload                                                                                                                  | :white\_check\_mark:                                 |
| JSON Token Path         | The JSON path of the data you want to extract for the Firebase reply.                                                                              | :white\_check\_mark:                                 |
| Target Variable         | The name of the variable that will hold the result of the action executed.                                                                         | :white\_check\_mark:                                 |

### Remarks

When requesting or uploading a full Firebase document, Xenioo will automatically translate each model into a simpler representation that will both speed up parsing and simplify representation.

As an example, let's have a look at the following Firebase Firebase document:

```javascript
{
    "name":"projects/somedb-14cf1/databases/(default)/documents/users/319daACFaz",
    "fields"{
        "full_name":{
            "stringValue":"Gian"
        },
        "age":{
            "integerValue":"48"
        }
    }
}
```

As you can see it's very complete, but also quite verbose and not very handy for quick variables reading. When accessing this document, Xenioo will automatically shrink the structure to a more concise version:

```javascript
{
    "Id":"319daACFaz",
    "full_name":"Gian",
    "age":48
}
```

&#x20;Note two things: first, the document id has been reduced to represent only the actual document final unique value. Second, the *age* field has been automatically translated in the projected model to the correct type, representing a number.

The same translation happens also in reverse. When using the second model to update a Firebase document, Xenioo will transform back the model to the Firebase format. Note that this is not mandatory: the Firebase Action supports both the default, Firebase native format and the Xenioo translated one.

When using QUERY mode, a [full structured query](https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#Filter) can be specified inside the Query Payload parameter. As an example, searching for a document where the field "FirstName" is equal to "Mary" would require a query like this:

```javascript
where:{
    fieldFilter:{
        field:{
            fieldPath:"FirstName"
        },
        op:"EQUAL",
        value:{
            stringValue:"Mary"
        }
    }
}
```

All of the actions that can be executed by this action can also be executed directly by code, using [specific methods](/actions-and-operations/integration/xenioo.bots.actions.base.executescriptaction/firebase-connection-methods.md) available in Xenioo [Cloud Scripting Action](/actions-and-operations/integration/xenioo.bots.actions.base.executescriptaction.md).

{% hint style="warning" %}
To avoid overload, when no filter is active, the action **will not** query all the records available in a given collection. Only the first 20 fields will be extracted. Do not use the LIST mode to access the full list of records and then search manually. Use a structure
{% endhint %}

### Trigger

This action does not trigger any event.

### Variables

Beside the value set to the selected *Target Variable* setting, this action is producing the following variables:

| Variable                     | Description                                                                             |
| ---------------------------- | --------------------------------------------------------------------------------------- |
| firebase\_list\_empty        | Set to true if the last command returned an empty list or false if any record was found |
| firebase\_last\_document\_id | Contains the last document id returned by  an UPDATE or CREATE database command         |

### Availability

Channel specific availability follows the table below:

| Channel          | Availability     |
| ---------------- | ---------------- |
| Facebook         | Fully Available. |
| WhatsApp         | Fully Available. |
| Telegram         | Fully Available. |
| Web              | Fully Available. |
| Alexa            | Fully Available. |
| Google Assistant | Fully Available. |
| Slack            | Fully Available. |
| API              | Fully Available. |

This action can be used only inside interactions and not as child of other actions. This action requires a [Premium Account](/basic-concepts/your-account/upgrading-from-free.md) to be used on a live chatbot.

### Further Reading

{% embed url="<https://www.xenioo.com/en/using-firebase-cloud-data-with-your-chatbot/>" %}

{% embed url="<https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#Filter>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs10.xenioo.com/actions-and-operations/integration/firebase-database-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
