![Working with “virtual” data types in Bubble](https://cdn.feather.blog?src=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%3A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252F480f0932-72ea-496f-a70d-3632da8d6e99%252Fc65282ef-4608-46fb-bfc3-2a89cdc56128%252Fvirtual_(1).png%3Ftable%3Dblock%26id%3Dd3cc914a-2c82-4faa-9285-acd1c6d94edb%26cache%3Dv2&optimizer=image&quality=80&width=280)
Do not index
Do not index
In data integrations, matching data types between the source and the destination tool is crucial. Proper setup in Bubble is essential for correctly interpreting data, particularly when dealing with unpredictable data structures, like those from a relational database like we explore in the SmartSuite plugin tutorial.
Eli introduced a concept of 'virtual data types' a few years ago (find out more here). This approach involves giving Bubble a sample format to properly handle incoming data. Users can create this format either within your plugin or externally. After setting it up, their next step is to upload it into Bubble. The rest of this guide will detail methods for generating these formats and explain how users can implement them.
Why not rely solely on the API Connector?
You might be wondering why there's a need for these steps and why the Bubble's API connector isn't sufficient.
The API connector is effective when the data format is consistent every time. However, in cases where we’re pulling information from a data source where users may have various combinations of columns and types, the format becomes unpredictable.
In such scenarios, the API connector isn't suitable for a generalized format approach.
1. Generating “virtual data types”
Generating virtual data types with external tools
There are various methods to generate the formats needed for Bubble plugins, and it's not always necessary to create an element or action within Bubble itself; this is more about adding convenience. Users can alternatively utilize external tools like Postman or Hoppscotch.
Additionally, if the tool you're integrating with provides a sample format, you can direct your users to use this as part of their setup. This approach is exemplified by the Xano Bubble connector. As Xano allows users to test API calls directly from Xano documentation, they can conveniently acquire the sample format needed from there.
Using the plugin to generate the virtual data type
You can also generate formats directly within the plugin. This method involves initiating a call to the service and then using all or part of the response as an example format. We use this approach in the How to build a SmartSuite plugin tutorial.
Handling the virtual data type from a Plugin
Handling the format once it's returned can vary. If using Bubble elements, a 'copy to clipboard' action can be integrated. For server-side actions, the format is returned as a value, necessitating user configuration on their Bubble page for access.
In our How to Build a SmartSuite Plugin tutorial, we showcase a server-side action that returns the format, which users then set up on a Bubble page. Here's an overview of this process:
First, users need to add the “API Connector” plugin for importing our table format.
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2Fe5b87479-6027-4b6f-b4b9-54c839172db8%2F480f0932-72ea-496f-a70d-3632da8d6e99%2F39591252-0be2-4e70-884a-30a24ceab7f0%2FUntitled.gif&optimizer=image&quality=80&width=280)
Next, they create an internal page to capture the format:
- Add a new page.
- Place a text element on the page.
- Set up a custom state called “format” for this text element, with a type of “text”.
- Assign “Text A's format” as the text element's value.
For a step-by-step visual, see the screen share below.
In the workflows section, they should:
- Add the 'SmartSuite - Fetch Table Format' action.
- Specify the 'TableId.'
- Include a second action to update the state of the text element to 'Result of Step 1's Table Format.'
Refer to the video below for a visual guide.
Finally, they can run the app and copy the format.
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2Fdea9d508-1e00-4192-bbf1-9b800082f06f%2F480f0932-72ea-496f-a70d-3632da8d6e99%2Fafbe4ce8-775f-4597-bc75-842f20094550%2FUntitled.gif&optimizer=image&quality=80&width=280)
2. Making actions work with virtual data types
Regardless of whether users generate the virtual data type through an external tool or your plugin facilitates the process, it's important to ensure that any objects your plugin subsequently returns are formatted in a way that that is compatible with those virtual data types. Bubble has specific ways of handling data types:
- For data types imported from the plugin, Bubble adds a prefix '_p_' to each key.
- For data imported through the API Connector (a common method when the data type isn't predetermined), Bubble uses the prefix '_api_c2_'.
You can see an example of this here. For a more detailed explanation, check out this Bubble forum thread (link).
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2F99f86e04-a302-4d2c-a27a-c21660a10682%2F480f0932-72ea-496f-a70d-3632da8d6e99%2F93feb951-0142-401c-9e1e-0145bf6f5e05%2FUntitled.png&optimizer=image&quality=80&width=280)
3. User configuration in Bubble
No matter how users generate the “virtual data type”, they need to upload it into the API Connector for Bubble to recognize the expected format from your plugin.
In the Bubble editor, go to the 'Plugins' tab and open the 'API Connector'. Choose 'Add another API' and name it. If the 'API Connector' isn't already in the project, users can add it by selecting 'Add plugins', searching for 'API Connector', and then clicking 'Install'
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2F627e7d85-7ae8-4b53-a865-c917be887757%2F480f0932-72ea-496f-a70d-3632da8d6e99%2F449f608b-33da-4188-8aba-d493e76fd6d1%2FUntitled.gif&optimizer=image&quality=80&width=280)
Rename the 'API Call' to something more descriptive. This name will be used as the data source type for tables, repeating groups, and other elements in Bubble
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2F730bc6d5-6622-4e42-984b-58b7d379bd20%2F480f0932-72ea-496f-a70d-3632da8d6e99%2Fc10efadb-9792-422c-af94-349ff2e40c3b%2FUntitled.gif&optimizer=image&quality=80&width=280)
Users should then enter the example format into the designated field and click 'Save'. This action will save the data type in the Bubble editor.
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2F24ae1719-7805-4b52-9d8a-47296d948e3a%2F480f0932-72ea-496f-a70d-3632da8d6e99%2Fc102c2ce-df36-4f52-a4d6-dfa91bdd0530%2FUntitled.gif&optimizer=image&quality=80&width=280)
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy-prod%2Fblock%2F14c29455-afa5-465a-a4ef-08850e25197d%2F480f0932-72ea-496f-a70d-3632da8d6e99%2F4d4f7475-cf45-4e41-b563-e43648420183%2FCleanShot_2023-11-29_at_13.14.242x.png&optimizer=image&quality=80&width=280)
And that covers it! Users will need to go through exercise anytime they change the field types or add new fields that they’d like displayed in Bubble.
And that's it, we've covered the essentials of handling virtual data types. I'm curious to hear about your approach – how do you tackle virtual data types in your projects? Drop me a line at hey@lunchpaillabs.com and let's discuss.