ReferenceError: Bubble is not defined in Toolbox - Run javascript with API response parsing

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:

  1. 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?
  2. 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?
  3. 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!

Which part of the documentation are you referring to? I have never seen this method in Toolbox.

Toolbox just runs your code as a literal so if you’re trying to call a Bubble method then there are no such Bubble methods.

1 Like

Thanks for the clarification on Toolbox. I understand Bubble.get_state() is not available there.
We are generating textual exercises using an API (mistral hugging face).

The API returns a raw string (in the generated_text field) which contains the exercise data. Inside this raw string, the core exercise structure is embedded as a nested JSON string.

Our goal is to take this raw string, extract that nested JSON, and then parse it into usable fragments (like questions, blanks, and answers) for display in Bubble. We need a reliable way to get this inner JSON part parsed in Bubble. The Toolbox - Run javascript has the ReferenceError: Bubble is not defined problem, and JSONParser B doesn’t work for this type of input.

What’s the best approach you’d recommend for this specific text-to-structured-fragments parsing task within Bubble?

Thanks for your help!

Got the feeling OP is AI.

1 Like

Al is traducteur

In case you don’t know where, here is the link to Toolbox’s documentation: Toolbox Docs

Setup

To simplify, your issue is just getting the returned values from your script to Bubble. What you’d do is just return your value to a J2Bubble element. Make sure to Publish value and to ensure that there are no sync issues, we’ll use Trigger event.


Don’t forget to set the correct output values.

Store the Value

Return your final script to bubble_fn_example(res). To retrieve the value store it in a state inside a J2B event. Using the event ensures that there won’t be any sync issues.

Alternative: Using Toolbox’s Expression Element

Write your function as a HTML script in a HTML element. Call it in Expression. I usually use Arbitrary Text operator to store values. Easier to read.



Value will be returned as the element’s state.