Welcome to this step-by-step guide on syncing your Bubble database with the Xano no-code platform. In this article, we'll walk through setting up the integration, creating a custom function in Xano, and importing data from the Bubble Data API into your Xano database. Let's get started!
Prerequisites
Before we begin, ensure you have the following:
- A paid Bubble account (required to access the Data API)
- A Xano instance set up
Step 1: Obtain Bubble API Credentials
To use the Bubble Data API, you'll need to gather some essential credentials from your Bubble account:
- Log in to your Bubble account and navigate to the "Settings" section, then click on "API."
- Copy the "Data API root URL" – you'll need this later.
- Enable the checkboxes for the data types (tables) you want to access from Bubble.
- Create an API key and copy it.
Step 2: Set Up Environment Variable in Xano
In Xano, you'll store the Bubble API key as an environment variable for easy access:
- In your Xano instance, go to "Settings" > "Manage."
- Click "Add New Variable" and name it something like "Bubble API key."
- Paste the API key value you copied from Bubble into the variable's value field.
Step 3: Create a Database Table in Xano
Next, you'll need to create a database table in Xano to store the data you'll import from Bubble. This table should mirror the structure of your Bubble data type (table):
- In the Xano database section, create a new table (e.g., "Customers").
- Add columns that match the field types in your Bubble data type. For example, if you have a "Geographic Address" field in Bubble, create an "Object" column in Xano with sub-elements for address, latitude, and longitude.
Step 4: Create a Custom Function in Xano
Now, it's time to create a custom function in Xano to fetch data from the Bubble Data API:
- In the Xano "Library" section, click on "Functions" and create a new function (e.g., "Bubble Import").
- Add an "External API Request" block to your function stack.
- In the URL field, enter your Bubble Data API root URL followed by the data type (table) name you want to import. For example: `https://your-bubble-api-url.com/data/api/v1/%s`, where `%s` will be replaced with your data type name.
- To authenticate the API request, add an "Authorization: Bearer" header with your Bubble API key using the `push` function on the `header` array:
header.push({
"key": "Authorization",
"value": "Bearer %s" + env.get("Bubble API key")
});
- Run the function to test the API connection and ensure you're receiving the expected response.
Step 5: Import Data into Xano
With the API connection set up, you can now import data from Bubble into your Xano database:
- In your function stack, access the API response using the `sub_path` filter to retrieve the list of records.
- Use a `for_each` loop to iterate over the list of records.
- Inside the loop, use the `get` filter to safely access fields from each record, setting a default value in case the field is missing.
- Call the "Add or Edit Record" function, passing the record's unique identifier (e.g., `_id`) as the lookup value.
- Map the record's fields to the corresponding columns in your Xano table.
- Run the function to import all records from Bubble into your Xano database.
Next Steps
Congratulations! You've successfully set up the integration between Bubble and Xano, allowing you to import data from your Bubble database into Xano. In the next part of this guide, we'll explore how to handle relationships and pagination, ensuring a complete and efficient data syncing process.
Stay tuned for more exciting updates and happy no-code development!