# Sort list with Airtable

## Sort list with Airtable

This is a step by step tutorial about adding sorting functionality to your lists using the Airtable API on Bravo Studio.

This tutorial contains screenshots from an old version of data binding in Bravo Studio. The functionalities remain the same as the current interface.

## Before you start

Here are some of the things you need to have ready before you begin this.

1. Figma or Adobe XD
2. An [Airtable account](https://airtable.com/)
3. A [Bravo Studio account](https://www.bravostudio.app/)
4. The [Bravo Vision](https://docs.bravostudio.app/good-to-know/faq/bravo-vision) app, either from Google Play Store or the iOS app store.

{% embed url="https://i.imgur.com/gDsORUI.mp4" %}

## 1. Setting up your designs with Bravo Tags

We will have a list of pantry items, where we will show the name, the quantity and the last time it was stocked up, and that is how we will be sorting them.

In **\*Item \[container]**, the **\[container]** is a Bravo tag that tells Bravo Studio that this is the layer containing the elements that will be used with your Airtable data.

{% hint style="info" %}
Why the **\*asterisk**? Well, these are the layers that will be populated with data. The only purpose of the asterisk is to allow those layers to **stand out** when we are **binding our data** to the designs in Bravo Studio. Alternatively, you can even do **DATA-Item Name** instead of **\*Item Name**. All we are doing is indicating.
{% endhint %}

![Layer Structure and Naming](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJCn-veDJs3p8tO%2FUntitled.png?generation=1627557676974931\&alt=media)

As you can see, we have 3 buttons for our sorting; Item name, quantity, and last stocked. We are sorting our data in ascending and descending order. So that's a total of 6 screens.

Connect each button to the respective screen and test out the prototype to make sure the flow is how you want it to be.

![Prototype with all the interactions](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoIzLFSehQl06bvI%2FUntitled%201.png?generation=1627557676902599\&alt=media)

## 2. Setting up your data

We will have this data with varying names, quantities, dates. That way when we sort it, we can see it in ascending and descending clearly.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ4dyVQSZXBZeo6%2FUntitled%202.png?generation=1627557676913915\&alt=media)

## 3. Working with Airtable and the API

On Airtable, go to your account generate your Airtable API key. You will need this in order to connect your data to Bravo Studio. Find more about it [here.](https://support.airtable.com/hc/en-us/articles/219046777-How-do-I-get-my-API-key-)

![](https://support.airtable.com/hc/article_attachments/360004970234/new-api-key-generation.gif)

Go to [https://airtable.com/api](https://airtable.com/api) while logged in to your Airtable account and it will show all the tables you have created in your workspace, and chose your table. You will be shown the page below. The Airtable API allows us to use the sort function.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ522Ko0bqXmqgn%2FUntitled%203.png?generation=1627557676966448\&alt=media)

This means creating a GET request link for each of the screens we built out in the design tool. It's not actually that complicated. Thankfully, Airtable added in their easy to use encoder that will create those links for us.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ6HIwNRPTHNF_Q%2FUntitled%204.png?generation=1627557676928765\&alt=media)

### Airtable API URL Encoder

Open up the [Encoder site](https://codepen.io/airtable/pen/rLKkYB) on a different tab and **don't close it**. It should automatically fill out the Base ID and Table Name. If not, your Base ID is on the Introduction tab of the API page for your table.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ7alI9N7w4hdIC%2FUntitled%205.png?generation=1627557676914703\&alt=media)

Scroll down to the **sort** section. This is the important part because now you will be creating the link for GET request for each sort function. It's a nifty little tool. Remember how many screens we had? Six screens. That is six GET requests. Enter your field name and it will generate the required link for the sort.

Now is a good time to open up a Google Docs, Note Pad, or Notion page and start copy pasting the links for **Ascending** and **Descending** for **Item Name, Quantity and Last Stocked.** We will need them in Bravo Studio.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ8AqVmyavIr3ul%2FUntitled%206.png?generation=1627557676935659\&alt=media)

## 4. Connecting Airtable to Bravo Studio

Open up Bravo Studio and click on **New Project**. Create a new app project with your Figma or Adobe XD file. Once you have done that, click on Data Library. This is where you will connect your Airtable to Bravo Studio. Click on **New Collection** and name it and hit save.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ9eTBjF0dATni8%2FUntitled%207.png?generation=1627557676974823\&alt=media)

Make a new GET request using one of your six URLS. Paste the URL, and you will notice I have something in my header. This is where you are authenticating your API requests. So go to the Headers section and set it up as shown below. Field on left will have **Authorization** and field on the right will have **Bearer YOUR\_API\_KEY.**

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJAFbcKpcdtKhgN%2FUntitled%208.png?generation=1627557676918318\&alt=media)

Hit Send and if all went well, it should successfully show you the sample data, like below. Now check all the fields you want to get your data from that will populate your design elements. Make sure to also check .data.records\[]. By default, it will be set to 0, you want to set it to **All.** That will show all the data from the Airtable on your designs.

**Repeat** this step for the 5 other URLs.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJBj0daB_frY-Ho%2FUntitled%209.png?generation=1627557677006886\&alt=media)

## 5. Binding your data to your designs

Now navigate back to your projects and open the design you just imported. It should look something like this. Select any screen to start binding your data to your design.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ-J2PKowNgwVpL%2FUntitled%2010.png?generation=1627557676957119\&alt=media)

From the collection dropdown we will select the Data Collection we just made and then it will pull up all the GET requests we created in that collection.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ0UOhx2XHZ2XtJ%2FUntitled%2011.png?generation=1627557676902419\&alt=media)

After that, underneath Data Content, you will see a blue link called **+ Add App Element.** Because our elements that will be populated with data is under the **\*Item** element, select that on the popup with the list of visual elements. It will show up under design element.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ1FwKQUDOlAU4a%2FUntitled%2012.png?generation=1627557676902341\&alt=media)

You will see a dropdown under **Bound Data** from there select Records\[]. Once you do that, a plus sign will appear right underneath it. Click on it and you will be greeted with the same visual element selector popup.

Now, you will select the elements with the _asterisks. In our case that is_ Last Stocked, _Quantity, and_ Item Name.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ2k_0w-C9UnWUr%2FUntitled%2013.png?generation=1627557676927871\&alt=media)

It should look something like this. Once you have added them, go to the dropdown menu and start binding the appropriate data to your elements.

![](https://1444025092-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fdocs%2F-MflzZokSi-YILxIPrTm%2F-MflzoJ3IdAeA04qW9tI%2FUntitled%2014.png?generation=1627557676910572\&alt=media)

Repeat the same steps for the 5 other screens.

## 6. Time to test on Bravo Vision

When you click on each of the buttons, it will display the items in ascending and descending order for Item Name, Quantity, and Last Stocked!

{% embed url="https://i.imgur.com/gDsORUI.mp4" %}

That's it! 🎉
