# API

The API functionality is similar to the one described in the provided link.

{% embed url="<https://docs.communeify.com/en/products/dmflow/tutorials/docs/bot-restapi.html>" %}

After generating an API key, copy it and include it in the header's `Authorization` field as `'Bearer ' + {{token}}`. Note that the key will be inaccessible after 15 minutes.

**API Endpoints:**

**1. Query Forms:**

* **URL:** `POST /_api/v1/formqa/search`
* **Header:** `Authorization: {{auth}}`
* **Request JSON:**

  ```json
  {
    "id": "",
    "tableId": "",
    "index": 0,
    "onlyReturnCount": false,
    "wheres": [{
        "name": "",
        "compare": "",
        "value": ""
      }
    ]
  }
  ```

<table><thead><tr><th width="138">REQUEST_PATH</th><th data-type="checkbox">Required</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>false</td><td>string</td><td>Primary ID</td></tr><tr><td>tableId</td><td>true</td><td>string</td><td>Table ID</td></tr><tr><td>index</td><td>true</td><td>number</td><td>Page Index</td></tr><tr><td>onlyReturnCount</td><td>false</td><td>boolean</td><td>Only response count, it's quickly.</td></tr><tr><td>wheres</td><td>false</td><td>array</td><td>conditions</td></tr><tr><td>wheres[0].name</td><td>true</td><td>string</td><td>Field Key</td></tr><tr><td>wheres[0].compare</td><td>true</td><td>enum</td><td>eq(Keyword use eq same as in), gt, lt, lte, gte</td></tr><tr><td>wheres[0].value</td><td>true</td><td>string</td><td>If It is date field(use seconds), number field use number.</td></tr></tbody></table>

We will support order and size in the future, default size is 20.

RESPONSE JSON

```
{
	"rc" : 0
	"error": "",
	"data": {
		"total_element": 0,
		"docs": []
	}
}
```

2. **Form Trigger Action**

* **URL:** `POST /_api/v1/formqa/action`
* **Header:**`Authorization: {{auth}}`

This API allows you to trigger actions based on form data. It has a rate limit of 100 executions per hour per trigger, including loop iterations. If the limit is reached, the API will still execute the final iteration in full, rather than stopping partway through.

**Request JSON:**

```json
{
  "parameters": {
    "product": "Product name",
    "price": 200,
    "quantity": 5
  },
  "triggerId": "",
  "tableId": "",
  "guestId": ""
}
```

<table><thead><tr><th>REQUEST_PATH</th><th data-type="checkbox">Required</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>parameters</td><td>true</td><td>object</td><td><p>{</p><p>"product": "Product",</p><p>"price": 200,</p><p>"quantity": 5</p><p>}</p></td></tr><tr><td>triggerId</td><td>true</td><td>string</td><td>Trigger ID</td></tr><tr><td>tableId</td><td>true</td><td>string</td><td>Form ID</td></tr><tr><td>guestId</td><td>false</td><td>string</td><td>Guest User ID</td></tr></tbody></table>

**Response JSON:**

```json
{
  "rc": 0,
  "error": "",
  "data": {
    "error": false,
    "success": true,
    "response": ""
  }
}
```

* **rc (number):** Return code. Non-zero values indicate an error.
* **error (string):** Description of the error if `rc` is non-zero.
* **data (object):** Contains the result of the action.
  * `error (boolean):` Indicates if the trigger encountered an error.
  * `success (boolean):` Indicates if the trigger successfully reached the END node.
  * `response (string):` Contains any additional response data.

#### Notes:

* **Initialization Time:** The server starts on-demand. The first API call may take some time, but subsequent calls will have normal response times.

**Deprecated Endpoint:** `/api/v1/bot/chat` is no longer in use.


---

# 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://docs-en.dmflow.chat/api.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.
