Hello everyone,
I’m facing a very frustrating issue with the Toolbox - Run javascript plugin and I’m hoping the community can help me, as I’m currently blocked.
Context:
I have an API call (HuggingFace Inference API, generate_exercise POST request) that is working perfectly. The API returns a JSON object where one field, generated_text, contains another nested JSON string (delimited by json\n** and **\n
).
The Bubble API Connector successfully receives the full response. I store the value of generated_text in a Custom State (Grammaire_Exercise’s raw_api_response_text), and this part is confirmed working (I’ve displayed it on the page to verify).
My Goal:
To extract the nested JSON string from raw_api_response_text and parse it to be used in a Repeating Group.
The Main Problem: ReferenceError: Bubble is not defined
I’m using a “Run javascript” step in my workflow to try and extract and parse this nested JSON. The code used is similar to this (simplified):
(function() {
var fullResponseString = Bubble.get_state(“Grammaire_Exercise”, “raw_api_response_text”);
// Code to extract the JSON between delimiters (json\n...\n
)
var innerJsonText = … ;
try {
var parsedData = JSON.parse(innerJsonText);
Bubble.set_state(“Grammaire_Exercise”, “parsed_exercise_list”, parsedData);
} catch (e) {
console.error(“Parsing error:”, e);
}
})();
Despite:
- The Toolbox plugin being installed and active.
- Using Bubble.get_state() and Bubble.set_state() which are the documented methods for Custom States.
- The JavaScript code being syntactically correct (verified).
- No parameters being set in the “Run javascript” action’s settings.
I consistently receive the error ReferenceError: Bubble is not defined in the browser console. This completely blocks me as I cannot interact with Custom States from JavaScript.
Secondary (but confusing) Issue:
I previously had a JSONParser B step (from another plugin, I believe) attempting to parse the response. It generated the error Element JSONParser B The Output type must be an API Connector type. I’ve since disabled this workflow step using the Only when: no condition, but this error still persistently appears in the logs, which seems unusual for a disabled step.
My Questions to the Community:
- Has anyone encountered the ReferenceError: Bubble is not defined error in Toolbox - Run javascript? What was the cause, and how did you resolve it? Is this a known issue with specific Bubble versions or the plugin itself?
- Is there a more robust and stable method within Bubble to extract and parse nested JSON (like {“key”: “
json\\n{...}\\n
”}) directly from an API Connector response, especially if Run javascript is unstable or JSONParser B is unsuitable? - Is it normal for an error related to an element (JSONParser B) to still appear in the console logs even if its corresponding workflow step is disabled?
I would be extremely grateful for any help or insights.
Thank you in advance!