Does the data API support nested data?

I’m trying to fetch an array of posts from:

https://[app].bubbleapps.io/version-test/api/1.1/obj/post

Each post object includes a user. I’m including the post creator to avoid a separate API call to the user’s endpoint.

However, the user field is simply returned as a string (the user’s ID), instead of a nested object.

Doesn’t the get API endpoint support nested data?

@emmanuel

Can you clarify what you’re asking for?

‘Post’ is a thing
A thing only has one creator so it will only ever be the Users Unique ID

If ‘Post’ has a list of other things then those will be in the JSON response as an array.

Personally… Another approach would be the USER endpoint and if the USER thing has the list of that users Posts they will be in the JSON response.

The creator field may contain a unique ID, but I’m adding a field of type User to the Post.

This is what’s being returned.

        {
            "Created Date": "2018-07-28T06:43:28.570Z",
            "Created By": "1532732071148x172520255204290140",
            "Modified Date": "2018-07-28T06:43:28.800Z",
            "text": "Brussels, Belgium.",
            "user": "1532732071148x172520255204290140",
            "_id": "1532760207662x451723858379276300",
            "_type": "custom.post"
        },

I want a nested user object as follows:

        {
            "Created Date": "2018-07-28T06:43:28.570Z",
            "Created By": "1532732071148x172520255204290140",
            "Modified Date": "2018-07-28T06:43:28.800Z",
            "text": "Brussels, Belgium.",
            "user": {
                "image": "//s3.amazonaws.com/appforest_uf/f1532732176106x133952857227995980/zuck.png",
                "name": "Tom Ford",
                "_id": "1532732071148x172520255204290140",
            },
            "_id": "1532760207662x451723858379276300",
            "_type": "custom.post"
        },

I’m still not quite following…

Are you saying the 'POST@ current endpoint is returning

    {
        "Created Date": "2018-07-28T06:43:28.570Z",
        "Created By": "1532732071148x172520255204290140",
        "Modified Date": "2018-07-28T06:43:28.800Z",
        "text": "Brussels, Belgium.",
        "user": "1532732071148x172520255204290140",
        "_id": "1532760207662x451723858379276300",
        "_type": "custom.post"
    },

and you want to return

{
“Created Date”: “2018-07-28T06:43:28.570Z”,
“Created By”: “1532732071148x172520255204290140”,
“Modified Date”: “2018-07-28T06:43:28.800Z”,
“text”: “Brussels, Belgium.”,
“user”: {
“image”: “//s3.amazonaws.com/appforest_uf/f1532732176106x133952857227995980/zuck.png”,
“name”: “Tom Ford”,
“_id”: “1532732071148x172520255204290140”,
},
“_id”: “1532760207662x451723858379276300”,
“_type”: “custom.post”
},

or are you indicating it is returning the JOSN and you can consume this data in the USER element

PIng me a PM with your API endpoint… Stick temporary token which you can change after I’ve had a look for you…

Hi @csblack, did you find a solution for this?

Thanks

1 Like

@jvelasquez, @csblack, @Bubbleboy: same question here.

Any solution yet?

To clarify (for my case at least):
I get a JSON response from my API endpoint with all Posts and each individual Post contains a “user” element.
The question is: is it possible to get the API endpoint to show all Posts with the nested data expanded (ie. where “user” expands to “user id”, “name”, etc.

An external piece of software getting data from the API endpoint probably doesn’t seem to have much use for a user-id coming from the bubble app’s database - but getting the user’s data (like name) would certainly be useful.

In my specific case I have many ‘nested’ Things that I would like the API to ‘spit out’ in one go.

@emmanuel - maybe you can shed some light on this?

Thank you all in advance!

I am looking for a solution to this also. In my case I need to get all of the data in one API call for a record.

I think that the confusion above comes from using the word Post as a type name as POST has a meaning in API calls.

In Bubble we have Data Types and and each “record” in a Data Type is a Thing. I want to retrieve a Thing and any related Things. Currently I just get the Thing and the ID of the related Things.

I have a Data Type call Payments. So in my case I am getting this response when I send a GET request to my payments endpoint:

{
    "response": {
        "results": [
            {
                "PymntTotal - Sum of pymnts": 70,
                "Internal receipt ID": 1,
                "Owner": "1532713071148x172519846281290140",
                "Payment method": "Bank Transfer",
                "Payment received": false,
                "Created By": "1518241101817x359411902410611500",
                "Created Date": "2019-02-08T18:03:53.580Z",
                "Modified Date": "2019-02-08T18:03:53.630Z",
                "_id": "1541054615617x742816549761800200",
                "_type": "custom.payments"
            }
        ],
        "cursor": 0,
        "count": 1,
        "remaining": 91
    }
}    

What I need is to expand the owner so that my response looks like this:

{
    "response": {
        "results": [
            {
                "PymntTotal - Sum of pymnts": 70,
                "Internal receipt ID": 1,
                "Owner": {
                    "name": "John Smith",
                    "email": "john@smith.com",
                    "_id": "1532713071148x172519846281290140"
                },
                "Payment method": "Bank Transfer",
                "Payment received": false,
                "Created By": "1518241101817x359411902410611500",
                "Created Date": "2019-02-08T18:03:53.580Z",
                "Modified Date": "2019-02-08T18:03:53.630Z",
                "_id": "1541054615617x742816549761800200",
                "_type": "custom.payments"
            }
        ],
        "cursor": 0,
        "count": 1,
        "remaining": 91
    }
}
2 Likes

@arnold.smyth Did you find a solution to the nested API call ? I am looking for the same and grateful if you could share your findings.

1 Like

No, and I actually re-stumbled into this issue again the other day. As far as I can tell, Bubble still doesn’t support nested JSON data.

@csblack Thanks for your reply! I came across this great plugin that generates nested JSON data. [NEW PLUGIN] Generate deep nested JSON from thing(s)

1 Like

@csblack & others: Did anyone ever find a solution?

It looks like the plugin recommended by @happyholz123 would be handy for some use cases, but isn’t applicable to the Data API. I believe that using the Data API is the only option for use cases where the API response comprises more than 50 things, which is the maximum supported in the Return Data from API action.