Hi there, I’ve used the Bubble API connector many times without issue, but right now, I’ve got a problem with an API format and using it in a repeating Group.
Here’s the format of the API response below. (It’s search results.)
As you can see we have “result” and then within that we have each result ID as child items, and then within those children we have then data we want.
This format means that the API connector treats each result item as a unique field, so multiple results return the format “37401615 title”, “37401563 title” etc. so I can’t use them in a repeating group.
Has anyone else ever experienced this? or have a workaround to use a format like this?
So a summary for anyone reading this with a similar issue. Bubble API connector is unable to work with this (fairly common) format of JSON API (Called “JSON Dictionaries”)
There are two options and BOTH start with setting the data type in your API connector to “text”.
Use Extract with Regex to get the data you want - this is not great but it works.
Find a plugin (not great either but it works) - search for JSON Parsers.
Wait for Bubble to support this kind of format. (very bad solution given they don’t seem interested in supporting it).
So in summary, it is a painful limitation of the API connector, but there are workarounds.
Thanks, yes, it’s most common for APIs to be formatted like your example above.
My previous work around was to use the XML data format (it is an option with this API) but Bubble broke the XML format during their update to v28, meaning I don’t get the data I need from the XML format anymore for this API, so this has been a painful journey for me to fix.
I would just create a plugin with server side action to handle the transformation of this data.
Something like this
async function(properties, context) {
const axios = require('axios');
try {
// Make the API call using axios
const response = await axios.get('https://example.com');
// Extract and transform the result
const resultObject = response.data.result;
const resultArray = Object.keys(resultObject).map(key => ({
id: key,
...resultObject[key]
}));
// Return the transformed result
return {
results: resultArray
};
} catch (error) {
console.error('Error making API call:', error);
throw new Error('Failed to make API call');
}
}