# \[Example] Retrieving data from Airtable (GET)

Bots are often used to show data from external sources to your user. An easy way to manage this data is by using [Airtable](https://airtable.com). Airtable is a tool that allows you to create a spreadsheet that you can talk to with an API.

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 %}

As an example we're going to be building a bot that shows information about chatbot meetups.

* The first thing we have to do is create some meetup data. In this example, we will be using [this Airtable](https://airtable.com/shrJGHyo1RZuJf72Z). Feel free to reuse it!

![](/files/-M6iYS1yddyb6GvruKyh)

* Start by building a short flow that states the purpose of the bot and that asks about which month the user wants to know meetup info.

![](/files/-M6iUmp-dFIzPFwS76ls)

* For the month question, make sure you're using an [input validation](/buildabot/flow-logic/dialog-state/user-input-bot-dialog.md) that saves the response as the`month` variable and that continues to the next step: an Action block.

![](/files/-M6iV7PiFbZCHx2Agq4i)

* Configure the Action block that is triggered after the input validation with a code plug-in. Add the "month" variable as an argument, as shown in the screenshot:

![](/files/-M6iWAybXbHUownei3ZB)

{% 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 %}

* Next, add this code snippet:

```javascript
const { month } = args;

const { records = [] } = await fetch(
  "https://api.airtable.com/v0/(yourAppId)/(yourTableName)",
  {
    method: "GET",
    headers: {
      Authorization: "Bearer (insert token here)",
    },
  }
).then((res) => res.json());

const found = records.filter((rec) => rec.fields.Month === month.toLowerCase());

const builder = ChatlayerResponseBuilder();

if (found.length) {
  builder.addSessionVariable("meetups", found);
} else {
  builder.addSessionVariable("nomeetups", found);
}

builder.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 %}

* This code block searches the table for a meetup in the month that the user said, and if it finds one, returns that information to Chatlayer.ai. If there is no meetup found, the `nomeetups` variable is saved to the session of the user.
* If you follow the flow to this point, it will look something like this:

![](/files/-M6iZVpvk5v2JYKQe3UO)

* And the following data is saved on the session:

![](/files/-M6iZcCw9kdzu8EwD6bs)

* Now all we need to do is show that data! Add a Go To at the end of the Action block where you have added the code block.
* Configure this Go To as following:

![](/files/-M6iZpm-3YxUmBUWP77r)

* This way, the user will get a different response if there are no meetups in the month that they've asked about.
* Finally, configure the messages in "show meetup info" to show the retrieved info from the Airtable sheet.

![](/files/-M6i_G-ak1RY6SgzazJQ)

* All done! You can now test the full flow.

![](/files/-M6i_LrF1VLt29jHLWEZ)


---

# 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/retrieving-data-from-airtable-get.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.
