# API calls

Chatlayer offers a solution to integrate your conversational agent with your backend logic, APIs, and databases. This enables you to create contextual, personalized, and actionable conversational experiences for your users.

## API integrations with Chatlayer

<img src="/files/-LjpVleKL7Qi1_dbJKRp" alt="How API integrations work." width="375">

{% hint style="warning" %}
Please note that the term *dialog state* refers to the same thing as [*block*](/buildabot/flow-logic/dialog-state.md), in the context of development tools.
{% endhint %}

<details>

<summary>How API integrations work on Chatlayer</summary>

1. A user types and sends a text message from a conversational agent interface channel (like Facebook Messenger, Web chat, etc) to Chatlayer.
2. The received message is going through Chatlayer’s NLP engine to detect the [intent](/navigation/natural-language-processing-nlp/intents.md) and the returned intent combined with user context will be used to retrieve the next block in the conversation.
3. Chatlayer’s [**API** step](#configure-your-api-step) can be added in a block to send an API request to your server with different types of static data and/or user session data.
4. Your server can respond with an object with 3 fields:

* `session`: a session object for saving retrieved user session data.
* `messages`: an array of messages to send back to the interface channel.
* `nextDialogstate`: a block state identifier to redirect the user to a next block in a conversation flow.

Session data will first be stored in the [user session](/bot-answers/session.md) so that you can use this data in messages defined in the array of messages or in messages defined in a dialog state defined as `nextDialogstate` in the API response. Second, messages will be sent, and afterwards the user is redirected to the `nextDialogstate`. All fields are optional.

</details>

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Configure your API step</strong></td><td></td><td></td><td><a href="/files/hMvCRP0MP2MFGAdNv05a">/files/hMvCRP0MP2MFGAdNv05a</a></td><td><a href="/pages/vbhtXmlO5EVKtzdORY6w">/pages/vbhtXmlO5EVKtzdORY6w</a></td></tr><tr><td><strong>Advanced API features</strong></td><td></td><td></td><td><a href="/files/RHxMMcZdTpIG2CTSRbIT">/files/RHxMMcZdTpIG2CTSRbIT</a></td><td><a href="/pages/-LmOkqUosgka4RsN08C8">/pages/-LmOkqUosgka4RsN08C8</a></td></tr><tr><td><strong>V1 API references</strong></td><td></td><td></td><td><a href="/files/l3lyzlpMLc5wN3Sou7MV">/files/l3lyzlpMLc5wN3Sou7MV</a></td><td><a href="https://api.chatlayer.ai/v1/docs">https://api.chatlayer.ai/v1/docs</a></td></tr></tbody></table>


---

# 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.chatlayer.ai/integrateandcode/custom-back-end-integrations.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.
