Automate project management with batch API calls

How to automate tasks with Baserow batch API calls

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.

What we’ll do

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:

  • Set up a Baserow database
  • Customize fields in Baserow
  • Create a database token
  • Reference database API documentation
  • Construct batch requests
  • Create a new Make scenario
  • Make an API call
  • Create new rows in bulk

Prerequisites

To complete this tutorial, you’ll need the following:

  • A Baserow hosted or self-hosted account.
  • A Make account.
  • Basic familiarity with Baserow and Make.

Let’s dive in!

Batch Baserow API calls with Make

1. Set up a Baserow database

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.

  1. Click on the + Create new button to add a new database to the workspace.
  2. Select the “Database” option from the dropdown modal.
  3. Give your database a descriptive name.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/a1245e26-7232-4def-9478-2917cfcecf31/Make\_database.webp

A default table will be added to the newly-created database. Now, let’s populate the Baserow database with some data.

2. Customize fields in Baserow

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:

  • category: The category in which the article was published.
  • headline: The title of the news article.
  • authors: A list of authors who contributed to the article.
  • link: The direct link to the original news article.
  • short_description: A concise abstract summarizing the news article.
  • date: The publication date of the article.

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,

  1. Click on the + button located just after the last visible field.
  2. Choose the desired field type and enter a name to label the field.
  3. Click on the Create button to finalize the process.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/735cae2a-1bcc-4ed9-94fa-c4e1c2a1f05d/Create\_field.webp

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.

3. Create a database token

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:

  1. Access your profile and then click on Settings.
  2. Click on the Database tokens tab.
  3. Click on the Create token + button.
  4. Input a name and choose the workspace.
  5. Click on the Create token button to generate a new database token for the workspace, which will be authorized for your user account.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/e20f48f2-383a-426c-9741-04b55efd19a4/create\_token.webp

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.

4. Reference database API documentation

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,

  1. Click on the vertical ellipsis beside the database.
  2. Select View API Docs from the menu.

The database API consists of different endpoints for specific actions.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/1b489b43-a41a-4629-af6d-895b5f32d7ba/Database\_API\_documentation.png

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.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/f68e414f-47f5-41e1-8596-2a0f40d6384e/connect\_Baserow\_with\_other\_software.webp

5. Construct batch requests

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.

6. Create a new Make scenario

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.

  1. Create a new Make account or log into your existing account.
  2. Go to the Scenarios tab and create a new scenario. Add the Baserow module scenario

7. Make an API call

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.

  1. Click the Add button next to the Connection type field.
  2. Enter your Baserow API URL. Find your Baserow API URL in your API documentation.

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.

  1. Enter the database token created.
  2. Click Save to create a connection.

Baserow’s “Make an API call” module communicates with the Baserow API and makes requests based on the task that has to be performed.

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/7ef30d59-4c4c-4efa-9438-90e930283687/Baserow\_make.webp

8. Create new rows in bulk

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:

  • API endpoint: Enter a path relative to [<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/
  • Method: To create rows in bulk, a POST request will be made to the endpoint.
  • Headers: The HTTP header used to indicate that the content of a request or a response is JSON data is Content-Type: application/json
  • Query string
  • Body: Paste the JSON text from the sample data into the corresponding field.

Thus, using the information available on the endpoint above, we populate the fields in the ‘Make an API call’ module like this:

https://baserow-backend-production20240528124524339000000001.s3.amazonaws.com/pagedown-uploads/dc40ab08-7085-4508-b7ed-d6cf793c8340/Screenshot\_2023-01-12\_at\_17.30.34.png

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!

Summary

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.

Other useful resources

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.