When working with large datasets, there are times when you need to handle data in bulk and treat a group of operations as one unit. Making individual API calls can be slow and ineffective.
To improve data retrieval and manipulation while optimizing performance and efficiency, you can use batch API calls. Instead of sending multiple requests to the API endpoint for each data item or operation, you can combine them into a single call. This improves performance and simplifies data retrieval and manipulation.
In this article, we’ll show you how to make batch API calls to enhance your operations.
In this tutorial, we’ll cover how to make an API call using Make. After doing this, we’ll explore the power of batch API calls and how they can supercharge data processing. We’ll cover the following steps:
To complete this tutorial, you’ll need the following:
Let’s dive in!
Log in to your existing Baserow account or create a new account if you don’t have one already.
Once you log in, you can access the dashboard to add workspaces and databases. Let’s start by creating a new workspace or adding a database to an existing workspace.
To create a new workspace, simply click on the + Create workspace button. Then, click on Add workspace to get started.
If you are just starting with Baserow, we recommend you read our support article on how to create a Group and how to add collaborators to your group.
Now that the workspace is set up, let’s create a database. You can either create a database from scratch or choose a template from our template library.
For this tutorial, we’ll walk you through the process of creating a database from scratch.
A default table will be added to the newly-created database. Now, let’s populate the Baserow database with some data.
Let’s create new rows in bulk. We will use a sample dataset containing news headlines from 2012 to 2022 sourced from HuffPost.
In this dataset, each record comes with attributes about the news articles:
We will create corresponding fields in the table, aligning them with these attributes. With Baserow, you have the flexibility to either create new fields or duplicate existing ones within your database.
To add a new field,
+
button located just after the last visible field.Once the field is created, you can further customize it and access additional options from the field’s dropdown menu.
To edit an existing field, click on the dropdown arrow next to its name, and the field configuration menu will open up for you to make changes.
Baserow makes authentication easy and secure for seamless integration with third-party applications.
To access Baserow data in Make, we’ll need to generate at least one database token. These tokens can grant specific permissions to create, read, update, and delete data up to the table level.
To generate a database token, follow these steps:
We will use the database token to access the endpoints provided in the database documentation. It’s only possible to use the endpoints if the database token has read, create, or update permissions.
The rules and functions to follow in order to make an API call are laid out in the database documentation. Understanding this will help efficiently manage data retrieval and manipulations through the API.
REST APIs are core operational tools that enable organizations and developers to consume and build on top of Baserow’s various database capabilities. Baserow API follows REST semantics, uses JSON to encode objects, and relies on standard HTTP codes, and machine and human-readable errors to signal operation outcomes.
To access the database API documentation,
⋮
beside the database.The database API consists of different endpoints for specific actions.
If you have a large dataset with thousands of rows of valuable information stored externally and you want to seamlessly integrate all this data into Baserow, dealing with each row individually can be time-consuming and tedious. In such cases, you’ll have to create each row one by one, making individual calls to POST
/api/database/rows/table/{table_id}/
.
However, what if users wanted to create multiple rows at once? That’s where batch API calls come in.
Now, let’s take a look at the API documentation to figure out the right way to construct batch requests and find out which endpoints support them.
API applications can perform numerous API requests in a single API call by using batch calls. A batch request is a single HTTP request that contains multiple API calls. Each part of the main HTTP request contains nested items.
Baserow batch mode allows creating, updating, or deleting multiple elements in one request. With batch API calls, you can significantly reduce overhead by consolidating multiple requests into one.
Here is an example of what a batch request looks like:
curl \\\\\\\\
-X POST \\\\\\\\
-H "Authorization: Token YOUR_DATABASE_TOKEN" \\\\\\\\
-H "Content-Type: application/json" \\\\\\\\
<https://api.baserow.io/api/database/rows/table/69213/batch/?user_field_names=true> \\\\\\\\
--data '{
"items": [
{
"id": 0,
"Name": "string",
"Description": "string",
"Project Type": 1,
"Code": "string",
"Campaign(s)": [
1
]
}
]
}'
The response for this batch operation will contain an array of items:
{
"items": [
{
"id": 0,
"order": "1.00000000000000000000",
"Name": "string",
"Description": "string",
"Project Type": {
"id": 1,
"value": "Option",
"color": "light-blue"
},
"Code": "string",
"Campaign(s)": [
{
"id": 0,
"value": "string"
}
],
"Brand Count": 0
}
]
}
Arrays are enclosed in brackets ([]), and their values are separated by a comma (,).
Next, we will automate the batch request with Make.
Make is a powerful automation platform that allows you to connect and automate workflows between various apps and services. Making batch API calls in Make enables you to iterate over a list of data and perform API calls for each item in the list.
A Make scenario is comprised of a series of modules that indicate how data should be transferred and transformed between apps/services.
Next, we will add the first module to the scenario.
Baserow endpoints are integrated into Make as app modules.
With the Make modules available for the Baserow app, you can “Create a Row.” However, what if you need to create multiple rows simultaneously without causing any disruptions to your workflow?
This is where the “Make an API call” module proves to be invaluable, as there isn’t a dedicated Make module specifically tailored for creating multiple rows.
We will use the “Make an API call” module to create multiple rows in the table.
If you are using the SaaS version baserow.io, the default URL is https://api.baserow.io, otherwise, replace the URL with your self-hosted URL.
Baserow’s “Make an API call” module communicates with the Baserow API and makes requests based on the task that has to be performed.
For this tutorial, we’ll use the /create
endpoint to create new rows. Now, let’s configure an API call to this Create row
endpoint.
To set up the “Make an API call” module for a Baserow API endpoint, we will call the Create row
endpoint with batch mode. This allows us to create a list of rows from external data.
POST
<https://api.baserow.io/api/database/rows/table/{table_id}/batch/?user_field_names=true>
To make a successful call to the API, input the data that the documentation provides into the module’s fields:
[<
https://api.baserow.io
>](<
https://api.baserow.io/
>)
. To define the URL of the request, it is important to note that you only need to provide the path relative to the full URL of the endpoint. In this case /api/database/rows/table/{table_id}/batch/
POST
request will be made to the endpoint.Content-Type: application/json
Thus, using the information available on the endpoint above, we populate the fields in the ‘Make an API call’ module like this:
Once all the fields are filled, you will need to click OK. The module is now fully set up to make an API request to the endpoint.
After doing this, you can run the scenario, execute the Make scenario, and send all your items to a Baserow database. Once the module is fully set up, execute it!
Making batch API calls can significantly enhance efficiency and performance when working with APIs. If you’re using Make to streamline your Baserow automation and want to create, update, or delete multiple rows at once, you can do this task by using the “Make an API call” module.
You can easily handle multiple rows simultaneously, making the process much more streamlined and productive. Batch API calls allow you to fetch or update multiple records all at once, making things faster and supercharging the overall performance. Databases can enforce data integrity, ensuring that data is stored in a consistent and standardized format.
In case you’ve run into an issue while following the tutorial, feel free to reach out to ask for help in the Baserow community.
What’s your use case? Tell us how you use Baserow.