Forum Documentation Showcase Pricing Learn more

Does the data API support nested data?


#1

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


#2

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.


#3

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"
        },

#4

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…


#5

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

Thanks


#6

@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!


#7

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
    }
}