In my previous blog, we explored how I built a smoothie ordering application using Snowflake, Python, Snowpark and Streamlit.
Customers could enter their name, select ingredients and submit an order to be saved in Snowflake. However, there was another feature we have not explored yet: nutritional information appeared whenever a fruit was selected.
What I found interesting was that this nutritional information was not stored in our Snowflake tables. Instead, we retrieved it from an external source using an API.
In this blog, I want to explore how we made this possible, starting with a simple request and gradually building towards retrieving information for every fruit selected by the customer.

1. What actually is an API?
API stands for Application Programming Interface. Before looking at the code, it is worth understanding what this means.
Imagine a school library. You want to know whether a particular book is available, so you give the librarian its title. The librarian searches the catalogue and returns information such as the author and availability.
You do not need to know how the catalogue is organised or how the information is stored. You simply need to know what to ask for. An API works in a similar way.
| School library example | Our application |
|---|---|
| Person requesting information | Python application |
| Title of the book | Fruit name |
| Librarian | API interface |
| Library catalogue | External data source |
| Book information returned | API response |
In our application, we are requesting information about a fruit rather than a book.

An API provides a way for different software systems to communicate without needing to understand everything about how each system works internally.
2. Where is our data coming from?
In the previous blog, our application relied on Snowflake for its data. We are now introducing a second source of information.
Snowflake:
- Provides the list of available fruits.
- Stores the customer’s smoothie order.
Smoothiefroot API:
- Provides nutritional information about each fruit.
Python communicates with both systems, while Streamlit displays the information to the customer.

We are bringing information from two different places into one application.
3. Making our first API request
To begin communicating with the API, we imported another Python library.
import requests
Think back to the libraries we used in the previous blog.
| Library | What we use it for |
|---|---|
| Streamlit | Building the user interface |
| Snowpark | Working with Snowflake |
| Requests | Making requests to external services |
Rather than trying to retrieve information for every selected fruit immediately, we started with one fruit: watermelon.
smoothiefroot_response = requests.get(
"https://my.smoothiefroot.com/api/fruit/watermelon"
)
On the right-hand side, we ask the API for information about watermelon. On the left-hand side, we store the response in a variable called smoothiefroot_response.
The requests.get() method sends an HTTP GET request to retrieve information. The final part of the URL identifies the fruit we are interested in.
https://my.smoothiefroot.com/api/fruit/watermelon
At this stage, we have made our first API request, but we have not yet displayed the nutritional information.
4. What has the API returned?
To see what the API returned, we used:
st.text(smoothiefroot_response)
The result looked like this:
<Response [200]>
When I first saw this, it was not immediately obvious what it meant. Where was the actual information about the fruit?
The number 200 is an HTTP status code. It indicates that the HTTP request was successful. Other status codes tell us about different outcomes.
| Status code | Meaning |
|---|---|
| 200 | Successful request |
| 404 | Requested resource not found |
| 500 | Internal server error |
Knowing that a request was successful is not the same as seeing the information returned. A 200 status code alone does not guarantee the data is what we expected. To access the information, we need one more step.
5. Accessing the information using JSON
We then introduced another method.
st.text(smoothiefroot_response.json())
The .json() method parses the JSON response body into Python data that we can work with. It does not send another API request.
This is where I started making connections with my second blog. Previously, we explored JSON inside Snowflake and looked at nested structures. We are now encountering JSON again, but from an external API.
Here is a shortened example of the information returned for an apple.
{
"name": "Apple",
"family": "Rosaceae",
"nutrition": {
"carbs": 14.8,
"fat": 0.21,
"protein": 0.19,
"sugar": 12.2
}
}
Notice how the nutritional values sit inside another section called nutrition. This is similar to the nested JSON structures we explored previously.
We can now see the difference between the response object and the information contained within it.
| Code | What it represents |
|---|---|
| smoothiefroot_response | Response object, displayed as <Response [200]> |
| smoothiefroot_response.json() | Parsed response body as Python data |

One tells us about the response, while the other allows us to work with the information returned.
6. Displaying the information in Streamlit
Although we can now see the nutritional information, displaying it as raw text is not particularly useful for a customer. We can use Streamlit to present the information in a familiar table format.
st.dataframe(
data=smoothiefroot_response.json(),
use_container_width=True
)
We are taking the parsed information returned by the API and asking Streamlit to display it as a table.

The use_container_width=True argument in our workshop code helps the table make use of the available space on the screen.
We have retrieved information from an external system and displayed it within our application. However, our request is still fixed to watermelon.
7. Making our API request dynamic
Look again at our original request.
requests.get(
"https://my.smoothiefroot.com/api/fruit/watermelon"
)
Regardless of what the customer selects, this request always asks for watermelon. We need the fruit name to change with the customer’s selection.
Imagine we have a Python variable:
fruit_chosen = "mango"
Instead of writing the fruit name directly into the URL, we can use the variable.
smoothiefroot_response = requests.get(
"https://my.smoothiefroot.com/api/fruit/"
+ fruit_chosen
)
Python joins the two pieces of text together to produce:
https://my.smoothiefroot.com/api/fruit/mango
If the value of fruit_chosen changes, the URL changes too.
| fruit_chosen | URL ending |
|---|---|
| mango | /fruit/mango |
| apple | /fruit/apple |
| watermelon | /fruit/watermelon |

Rather than writing a separate request for every possible fruit, we reuse the same code and change the value of the variable. For now, we assume the fruit names match what the API expects.
8. What if the customer selects multiple fruits?
In the previous blog, we explored how selected ingredients are stored in a Python list. Imagine the customer selects three fruits.
ingredients_list = ["mango", "apple", "watermelon"]
We want to display nutritional information for all three fruits. This is where our Python loop becomes useful again.
for fruit_chosen in ingredients_list:
st.subheader(
fruit_chosen + " Nutrition Information"
)
smoothiefroot_response = requests.get(
"https://my.smoothiefroot.com/api/fruit/"
+ fruit_chosen
)
st.dataframe(
data=smoothiefroot_response.json(),
use_container_width=True
)
Rather than trying to understand the entire block at once, we can follow each iteration.
First iteration — Mango: Python creates a heading, requests nutritional information for mango and displays the results.
Second iteration — Apple: Python repeats the same instructions, this time for apple.
Third iteration — Watermelon: Python repeats the instructions again for watermelon.
The result is three separate sections of nutritional information in our application, assuming the requests succeed.

Why indentation matters
This was something I spent more time understanding when revisiting the application. The API request and display instructions are indented inside the loop, so they repeat for every selected fruit.
If we moved the API request outside the loop, it would run only once after the loop finished. In the previous blog, we deliberately placed the SQL INSERT outside the loop because we wanted to save one complete order rather than a separate order for each fruit.
| Inside the loop | Outside the loop |
|---|---|
| Request information for each fruit | Work with the completed order |
| Display each fruit’s nutrition | Save one order when submitted |
| Repeat an action | Perform an action once afterwards |
Understanding this distinction helped me see why indentation matters in Python. It changes what the application actually does, rather than simply making the code look organised.
9. What happens if the API cannot find the information?
So far, we have assumed that every request works successfully. But what happens if the API does not recognise a fruit, or if the external service is temporarily unavailable?
Our application might be unable to display the nutritional information. Unlike our own database, an external system is not entirely within our control.
One way to investigate a problem is to check the status code returned by the API.
st.write(smoothiefroot_response.status_code)
This can give us an indication of whether the HTTP request was successful. If the connection itself fails, there may not be a response to inspect.
A more developed application would also handle unsuccessful requests and display a helpful message to the customer. For now, the important concept is that we should not assume every API request will return the information we expect.
10. When two systems use different names for the same thing
As we continued developing the application, we encountered another problem. Some fruit names stored in Snowflake did not match the names expected by the API.
| Fruit name in Snowflake | API search value |
|---|---|
| Apples | Apple |
| Blueberries | Blueberry |
| Jack Fruit | Jackfruit |
| Strawberries | Strawberry |
As humans, we understand that Apples and Apple refer to the same fruit. However, the API might expect a specific name. Simply using the customer’s selected fruit name was not always enough.
To address this, we introduced an additional column in our Snowflake table called SEARCH_ON. We now had two values:
FRUIT_NAME— the name displayed to the customer.SEARCH_ON— the name used when requesting information from the API.

In the completed application, we used the search value rather than the selected fruit name when building the request. But how does Python find the corresponding search value?
To help us do this, we introduced another Python library called Pandas. It allows us to work with and manipulate data in Python. In our application, we used it to find the mapping we had prepared in Snowflake.
Rather than introducing all the code here, I explore Pandas, Snowpark DataFrames and the complete mapping process in Part 5.
11. Putting everything together
Our smoothie application has evolved from an interface that reads and writes information in Snowflake into an application that also retrieves information from an external source.
Each technology has its own responsibility.
| Technology | Role in our application |
|---|---|
| Snowflake | Stores fruit options and customer orders |
| Python | Controls the application logic |
| Snowpark | Allows Python to work with Snowflake |
| Requests | Retrieves information from the external API |
| Streamlit | Displays information and collects customer inputs |

What I find particularly interesting is that customers do not need to understand any of these technologies. They simply select a fruit and the relevant information appears on screen. Behind that simple interaction, several technologies are working together.
What have we learned?
| Concept | What it allows us to do |
|---|---|
| API | Communicate with another software system |
| requests.get() | Request information from an external source |
| Status code | Understand the outcome of a request |
| .json() | Parse JSON into Python data |
| Dynamic URL | Change the information we request |
| for loop | Repeat a request for every selected fruit |
| st.dataframe() | Display information as a table |
| Data mapping | Help systems work with compatible values |
Final thoughts
When I first started learning about APIs, they seemed like another technical concept that I needed to understand independently. Building this application helped me see how APIs connect with things I had already learned.
JSON was no longer just something I had explored inside Snowflake. Variables allowed me to change the information being requested, and Python loops allowed me to retrieve information for multiple fruits without repeating the same code.
Streamlit allowed me to present that information in a way that a customer could easily understand.
For me, revisiting the code after completing the workshop was just as valuable as building the application itself. It gave me an opportunity to understand why the code was written in a particular way, rather than simply knowing that it worked.
In the final part of this series, I explore how we used Snowpark and Pandas together to solve the problem of mapping information between Snowflake and an external API.
Snowflake for Beginners Part 5: Understanding Snowpark, Pandas and Mapping Data Between Systems
The complete smoothie application code is available on my GitHub repository.
