# 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

![How API integrations work.](https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LLTwFwbOqJj4dDhg8Ju%2F-LjpUT_edCWf-bzj1EAX%2F-LjpVleKL7Qi1_dbJKRp%2Fimage.png?alt=media\&token=06efa4e5-b2f6-4bde-8fd2-a00cca7ed4d0)

{% hint style="warning" %}
Please note that the term *dialog state* refers to the same thing as [*block*](https://docs.chatlayer.ai/buildabot/flow-logic/dialog-state), 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](https://docs.chatlayer.ai/navigation/natural-language-processing-nlp/intents) 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](https://docs.chatlayer.ai/bot-answers/session) 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="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FHNjGxFJUc0PBkG7W9NGm%2FScreenshot%202024-09-05%20at%2013.55.11.png?alt=media&#x26;token=c91b1a0c-962d-465d-87e4-3660b74552f5">Screenshot 2024-09-05 at 13.55.11.png</a></td><td><a href="custom-back-end-integrations/configure-your-api-integration">configure-your-api-integration</a></td></tr><tr><td><strong>Advanced API features</strong></td><td></td><td></td><td><a href="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F2O2fnyzQieeFdq5LYRGk%2FScreenshot%202024-09-05%20at%2013.47.11.png?alt=media&#x26;token=05ee7015-add3-40d4-a03f-4b90dcf710d2">Screenshot 2024-09-05 at 13.47.11.png</a></td><td><a href="custom-back-end-integrations/advanced-api-integrations">advanced-api-integrations</a></td></tr><tr><td><strong>V1 API references</strong></td><td></td><td></td><td><a href="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FWRrztFIdgDODWcv5bfQQ%2FScreenshot%202024-09-05%20at%2015.03.47.png?alt=media&#x26;token=c9c6d404-03a7-45ed-82b1-f4d5fb6279de">Screenshot 2024-09-05 at 15.03.47.png</a></td><td><a href="https://api.chatlayer.ai/v1/docs">https://api.chatlayer.ai/v1/docs</a></td></tr></tbody></table>
