Array not detected in JSON response - Bubble API Connector

I am hitting the RouteXL API RouteXL API | RouteXL to optimise Routes using the Bubble API Connector. Unfortunately, the JSON response from the API adds a Key to each array list item and doesn’t use square brackets. This means that the response is being detected as multiple fixed fields rather than a list of things (see the image below which shows the response I get in red). The response in blue is where the response has been hacked to remove the Array Keys and add square brackets.

This is the response API to force Bubble API connector to find a ‘list’:

{
  "id": "4T4446Pj",
  "count": 4,
  "feasible": true,
  "route": [
    {
      "name": "The Hague, The Netherlands",
      "arrival": 0,
      "distance": 0
    },
    {
      "name": "The Hague, The Netherlands",
      "arrival": 5,
      "distance": 3.9
    },
    {
      "name": "Uden, The Netherlands",
      "arrival": 93,
      "distance": 137.1
    },
    {
      "name": "Sint-Oedenrode, The Netherlands",
      "arrival": 112,
      "distance": 160.5
    }
  ]
}

But this is the response I get from the API:

{
    "id": "ExEJ6I4P",
    "count": 4,
    "feasible": true,
    "route": {
        "0": {
            "name": "The Hague, The Netherlands",
            "arrival": 0,
            "distance": 0
        },
        "1": {
            "name": "The Hague, The Netherlands",
            "arrival": 5,
            "distance": 3.8
        },
        "2": {
            "name": "Uden, The Netherlands",
            "arrival": 100,
            "distance": 137.1
        },
        "3": {
            "name": "Sint-Oedenrode, The Netherlands",
            "arrival": 118,
            "distance": 158.1
        }
    }
}

Is there any way to get the API connector to detect this style of array (which is valid JSON) so I can use the response in a repeating group/database list of things, etc.?

The issue is not Bubble and Bubble is totally right. This is not an array but an object. You cannot use Bubble API Connector for this kind of response. You need to creat your own plugin probably or use another tool.

2 Likes

Thank you @Jici

That is a shame. I can process the API in PHP and really hoped I could do it with Bubble as it is far easier to work with!

I have made a request to the API provider to provide a different format to be compatible with Bubble in the future. Perhaps, they will make a change as it’s a helpful API :crossed_fingers:

Yes, very annoying.

I think this may help?

2 Likes

That was a Boss video @NigelG ! Great stuff! :+1:

1 Like

Thank you @NigelG Helpful to see the same problem being found on other APIs

It looks like Integromat (now make.com) could be a way to go. I have started to use Google Directions API instead: Getting directions through the Directions API  |  Google Developers

This seems to have most of the functionality I was hoping for with a JSON response Bubble can parse correctly :+1: It’s not free like the RouteXL version though… :grimacing:

1 Like

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