Unexpected 400 Error in API Connector with Geopify – Possible Hidden Characters?

Hello,

I’ve set up an integration between Bubble and the Geopify Route Planner API using the API Connector. It’s a POST request with dynamic parameters. The request body looks like this:

{
    "mode": "drive",
    "agents": [
        {
            "id": "Routey",
            "start_location": [
                <homebase_longitude>,
                <homebase_latitude>
            ],
            "end_location": [
                <finishbase_longitude>,
                <finishbase_latitude>
            ],
            "time_windows": [
                [
                    <starttime_user>,
                    86400
                ]
            ]
        }
    ],
    "shipments": [
        <shipments_array>
    ]
}

The workflow step that builds the dynamic parameter array is structured like this:

(body) homebase_longitude:-79.4270925
(body) homebase_latitude:43.844774
(body) finishbase_longitude:-79.4270925
(body) finishbase_latitude:43.844774
(body) starttime_user:0
(body) shipments_array:{"id": "1740548256333x704081110796861400", "pickup": {
                "location": [
                   -79.4270925,
                    43.844774
                ],
                "duration": 300
            }, "delivery": {
                "location": [
                    -79.3803654,
                    43.6415938
                ],
                "duration": 900
            }}

However, I’m getting the following error:

Workflow error - The service Geopify API - Route Planner API call just returned an error (HTTP 400). Please consult their documentation to ensure your call is set up properly. Raw error: {“statusCode”:400,“error”:“Bad Request”,“message”:“Unexpected token \ in JSON at position 506”}

What I’ve Checked:
The JSON output passes validation in JSONLint, meaning there are no visible syntax errors.
The reported error references position 506, but some of my test payloads contain fewer than 400 characters (excluding commas), so the reference seems inconsistent.
Data Sources:
All data used in the request is retrieved from a temporary database table created specifically for assembling this JSON array.
The coordinates are fetched directly from the database without modifications.
The <shipments_array> is built using three pre-formatted text blocks, combined via Arbitrary text to ensure the correct structure.
The final array is assembled into a field using JSON_array with “join with ‘,’” before sending the request.
Here is an actual JSON request output displayed on-screen before sending:

{
    "mode": "drive",
    "agents": [
        {
            "id": "Routey",
            "start_location": [
                -79.3803887,
                43.6510327
            ],
            "end_location": [
                -79.3803887,
                43.6510327
            ],
            "time_windows": [
                [
                    0,
                    86400
                ]
            ]
        }
    ],
    "shipments": [
        {"id": "1740544027934x507496224237551600", "pickup": {
                "location": [
                   -79.3803887,
                    43.6510327
                ],
                "duration": 300
            }, "delivery": {
                "location": [
                    -79.6085507,
                    43.5714273
                ],
                "duration": 900
            }},{"id": "1740544048140x629414809095372800", "pickup": {
                "location": [
                   -79.6085507,
                    43.5714273
                ],
                "duration": 300
            }, "delivery": {
                "location": [
                    -79.3847251,
                    43.6525022
                ],
                "duration": 900
            }},{"id": "1740544060674x298290248075444200", "pickup": {
                "location": [
                   -79.3803887,
                    43.6510327
                ],
                "duration": 300
            }, "delivery": {
                "location": [
                    -79.3708368,
                    43.6434596
                ],
                "duration": 900
            }}
    ]
}

Potential Issue:
I suspect Bubble might be inserting hidden characters into the request, even though they do not appear when inspecting the JSON output step-by-step or displaying it in a text field on the page.

Questions:

  • Does Bubble insert any hidden characters that are not visible in step-by-step inspection or text field outputs?
  • Are there known issues when assembling JSON arrays using Arbitrary text and join with “,” that could be causing formatting errors?
  • Is there a way to log the exact raw request Bubble sends to Geopify for further debugging?

Any insights would be greatly appreciated!
Thanks!

I didn’t find how to DM here on Bubble Forum, so @marcelo.bidoia.santos just tagged you if you have a chance to take a look

Can you paste your json using ``` around it so it can easily be copy and parsed?

What I guess is that Bubble is adding new line (/n) or something like that. Can you share where you enter your JSON in bubble and how it set? try to remove all spaces and new line (for example:
{"key":"value","key2":"value 2"}instead of

{
    "key": "value",
    "key2": "value 2"
}
1 Like

Thank you, didn’t know about ```. Fixed.

If I got it correctly, I entered it into the Arbitrary text on one of the steps on the Workflow when I added this data to the Temporary Database Table. Example:

"delivery": {
                "location": [
                    Result of step 1 (Create a new Loca...)'s Longitude,
                    Result of step 1 (Create a new Loca...)'s Latitude
                ],
                "duration": 900
            }

You were totally right about the spaces and new lines. Everyone – from the devs around to ChatGPT – kept saying it doesn’t matter, but clearly, it does! I really appreciate your help with this! Thank you so much!

1 Like

Sorry man I didn’t had the chance to see your mention before. But it seems like you’ve got the solution. Great, hope it’s working fine! If you need anything else just reopen it :slight_smile: