# \[Example] Sending data to Airtable (POST)

Data gathered inside of bots is often sent to an external database. An easy way of doing this is by ingrating with [Airtable](https://airtable.com). Airtable is a tool that allows you to create a spreadsheet that you can talk to with an API.

{% hint style="info" %}
Please note that the term *dialog state* refers to the same thing as *block*, in the context of development tools.
{% endhint %}

In this tutorial we will set up an integration with Airtable. Because of all the code it looks quite technical, but in fact it's pretty easy.

{% hint style="info" %}
If you're new to using variables in Chatlayer.ai, follow [this](broken://pages/-LLTwJA9WiK4ksc3r6ZI) tutorial first.
{% endhint %}

* Start by building a short flow that you use to gather some data about your user, for example:

![](/files/-M-QHyYIWIlIVEIjBB38)

* This flow adds the variables "customerType" and "firstName" to the session of the user.

![](/files/-M-QIDlYQP0ZnyC02wgU)

* Set up an Airtable that has a column for each variable you want to save. Rows will be added for each customer.

![](/files/-M-QJC8zvRc8JJRy3nmG)

{% hint style="info" %}
In this tutorial, we will be using [this Airtable](https://airtable.com/invite/l?inviteId=invSGcyaorwSSPjLi\&inviteToken=a6d2dc90da0a95019886b059a10323d827520aa1b46dcf2c528756c3e120189c). Feel free to reuse it!
{% endhint %}

* At the point in the flow where you want to send the data to Airtable, add an Action containing a Code plugin.

{% hint style="info" %}
Want to learn more about the possibilities of the Code plug-in? You can find it [here](/integrateandcode/code-action.md).
{% endhint %}

* In our example, we want to send the customer's type and first name. Furthermore, we want to jump to another bot dialog as soon as the data has been sent. Start by adding these parameters at the top of your code editor.

![](/files/-M-QKhZlCz-hZdO4c8JV)

* Then add the code below to the plugin and save your Action dialog.

```javascript
const body = {
    "records": [{
        "fields": {
            "First Name": args.firstName,
            "Customer Type": args.customerType
        }
    }]
}
const airtableResult = await fetch('https://api.airtable.com/v0/(yourAppId)/(yourTableName)', {
    method: 'POST',
    body: JSON.stringify(body),
    headers: {
        'Authorization': 'Bearer (insert token here)',
        'Content-Type': 'application/json'
    }
}).then(r => r.json())

ChatlayerResponseBuilder()
    .setNextDialogState(args.nextDialogState)
    .send()
```

{% hint style="warning" %}
Remember to get the right app id, table name and bearer token for your Airtable. You can find it [here](https://airtable.com/api).
{% endhint %}

* Et voilà! Now, every time a user goes through your flow, their data will be sent to Airtable, and they will continue on to the Success bot dialog.
* If there are any errors with your connection to Airtable, you can find them in the Error logs tab in Chatlayer.ai.

![](/files/-M-QGpdscZHQddl5ltw9)


---

# 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/code-action/airtable.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.
