Regex returns "0" from an API raw body

Hi- so I’m pulling the Stripe FX API to convert the foreign currency to USD before going into checkout. I had to use regex to get what I want (“exchange_rate”) from API because the currency code changes each call, so I couldn’t use the normal output.

It works fine when I was just using input/text elements to test. However, when I integrated it into the workflow, it would return “0” to my data field. I’m not sure what I’m doing wrong.


Edit 1 It seems to be a Bubble API intake problem. I pulled the workflow to the frontend and take a look what’s going on. It seems if I deviate away from Mexican pesos, Bubble is returning the entire API output as empty:

It’s a problem on Bubble’s end because when I checked Stripe’s developer console. It’s returning this output:

{
“id”:
“fxq_1RI0fQR6aaZt6bKXCvuCr4j9”,
“object”:
“fx_quote”,
“created”:
1745642924
,
“lock_duration”:
“none”,
“lock_expires_at”:
null,
“lock_status”:
“none”,
“rates”: {
“cop”: {
“exchange_rate”:
0.000233887,
“rate_details”: {
“base_rate”:
0.000236249,
“duration_premium”:
0,
“fx_fee_rate”:
0.01,
“reference_rate”:
null,
“reference_rate_provider”:
null,
},
},
},
“to_currency”:
“usd”,
“usage”: {
“payment”: {
“destination”:
null,
“on_behalf_of”:
null,
},
“transfer”:
null,
“type”:
“payment”,
},
}



Raw body:
{
“id”: “fxq_1RI0JUR6aaZt6bKXFSw9EecU”,
“object”: “fx_quote”,
“created”: 1745641564,
“lock_duration”: “none”,
“lock_expires_at”: null,
“lock_status”: “none”,
“rates”: {
“brl”: {
"exchange_rate": 0.174077, < trying to pull this number
“rate_details”: {
“base_rate”: 0.175835,
“duration_premium”: 0,
“fx_fee_rate”: 0.01,
“reference_rate”: 0.175898,
“reference_rate_provider”: “ecb”
}
}
},
“to_currency”: “usd”,
“usage”: {
“payment”: {
“destination”: null,
“on_behalf_of”: null
},
“transfer”: null,
“type”: “payment”
}
}`

Solved!

Got it — thanks for the clarification.
Stripe is returning the data, but Bubble is failing to show it because of dynamic keys in the response.
This makes perfect sense now.


:fire: Here’s Exactly What’s Going On

  • Stripe returns a normal JSON, like:
    {
      "quotes": {
        "mxn": {
          "exchange_rate": 0.058
        }
      }
    }
    
  • BUT quotes contains a dynamic key ("mxn", or "eur", "brl", etc.), and Bubble cannot parse dynamic object keys unless they are predefined at API initialization.

Bubble expects a fixed key structure.
If the key (like "mxn") changes and wasn’t captured when you initialized the API call, Bubble acts like the response is empty.


:bullseye: How to 100% fix this:

You have two solid options:


:pencil: Option 1: Set Data Type to Raw Text, Then Extract Manually

If you don’t care about parsing the whole object manually.

  1. In your API Connector, set Data typeText (not JSON).
  2. Leave Body the same (send it as JSON).
  3. When you receive the API response, it will come as raw text.
  4. Use Regex to pull the exchange_rate out.

Example regex:

"exchange_rate":\s*([0-9.]+)

In Bubble:
Result of API call: Extract with Regex (pattern above).

:white_check_mark: This way, it works no matter what currency you’re dealing with.


:pencil: Option 2: Create a Backend Workflow that Parses It

If you want something more “Bubble native” and clean.

  1. Make a Backend API workflow (e.g., “Get FX Rate”).
  2. In that backend workflow:
    • Accept the dynamic currency input.
    • Call Stripe.
    • In the backend, use :formatted as JSON and :find and replace or basic parsing tricks.
    • Return just the exchange_rate.

:white_check_mark: Then your frontend just calls the backend workflow, and gets back a clean Number field.


:pushpin: Key Takeaway

Bubble doesn’t know how to handle dynamic key names in JSON unless you predefine them.

When the key (“mxn”, “eur”, etc.) changes dynamically, Bubble thinks the object is invalid, and it displays nothing even if Stripe is sending good data.


:test_tube: If you want a quick fix

Go with Option 1 (Raw Text + Regex) — it’s faster and easy to implement without backend stuff.

Would you like me to write the exact regex you can paste into your Bubble “Extract with Regex” field? :fire: (takes 2 seconds)
Just say yes if you want it! :rocket:

This topic was automatically closed after 70 days. New replies are no longer allowed.