Returning data via API?

HI Everyone,

Is there a way to return data from from a bubble API call? I know I can expose the data itself via settings but, I’d like to do some preprocessing/filtering and access controls before sending it over.

Ideally, the API endpoint is hit, the workflow is triggered to filter results, and then returned in a JSON message.

Is this possible?

Yeah, you do that with the POST side of Bubble’s API. Any backend workflow can be exposed as a POST endpoint.

Thanks Keith. I have a API and can access it, but how do I read from a DB and send it as a json? The options I see are to do things to the data. Is there a option to just read/send as a result?

The “Return data from API” (under Data (Things)) action is where you define what your endpoint should return. Use it to construct the response your endpoint provides. This interface is the JSON response builder.

Here’s a quick example:

Here’s the resulting response to a successful query of my endpoint:

{
    "status": "success",
    "response": {
        "some_param": "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//sebbo.net//ical-generator//EN\r\nNAME:no name provided\r\nX-WR-CALNAME:no name provided\r\nBEGIN:VEVENT\r\nUID:81fn@grupz.com\r\nSEQUENCE:0\r\nDTSTAMP:20200625T220611Z\r\nDTSTART:20200622T195717Z\r\nDTEND:20200624T070000Z\r\nSUMMARY:Event 1 sum\r\nDESCRIPTION:Event 1\r\nURL;VALUE=URI:https://example.com/event1\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:zowc@grupz.com\r\nSEQUENCE:0\r\nDTSTAMP:20200625T220611Z\r\nDTSTART:20200630T070000Z\r\nDTEND:20200708T070000Z\r\nSUMMARY:Event 2 sum\r\nDESCRIPTION:Event 2\r\nURL;VALUE=URI:Event 2 URL\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:rxsf@grupz.com\r\nSEQUENCE:0\r\nDTSTAMP:20200625T220611Z\r\nDTSTART:20200812T070000Z\r\nDTEND:20200814T070000Z\r\nSUMMARY:Event 3 sum\r\nDESCRIPTION:Event 3\r\nURL;VALUE=URI:Event 3 URL\r\nEND:VEVENT\r\nEND:VCALENDAR",
        "key2": 3
    }
}
3 Likes

aghh that’s brilliant. Thank you.

Are you hitting the limitations of return data from api(I think it limits to 50 results). Is your event count for that?

Well, as you can see, the response here (which is literally just an example for you) isn’t returning arrays, it’s returning scalar values.

Of course you can always just construct your own response and send that back as text (a little bit of scripting may be required).

The restriction described here (Introduction - Bubble Docs) keeps folks from doing stupid stuff like exporting their entire database.

The point of the POST API in Bubble is to construct API’s for doing things like, “give me the Calendar for Rental Listing x”, not “give me all the Calendars in the database”.

If you send a Thing to return data, if the Thing has fields on it that are lists (arrays), those fields are not limited to 50 items (if they are simple data types, not Things). Fields that are Things themselves do not get decomposed into their component values, but are returned as the Unique IDs of those Things.

Here’s an example where I constructed a Thing (“Number List”) which has one field on it – a list of numbers. In this particular example, this Number List’s Numbers field has 1000 values. As you can see, they get transmitted just fine:

Response (at the end, you’ll observe how the User who created this object [the “Created By” field] comes across – as that User’s unique ID). If we needed to get certain data about the User we would create a different endpoint (or use the Data API - which I never use, BTW) to simply query for that User. Anyway, all of that should be enough to get you going, right?:

{
    "status": "success",
    "response": {
        "some numbers": {
            "numbers": [
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                19,
                20,
                21,
                22,
                23,
                24,
                25,
                26,
                27,
                28,
                29,
                30,
                31,
                32,
                33,
                34,
                35,
                36,
                37,
                38,
                39,
                40,
                41,
                42,
                43,
                44,
                45,
                46,
                47,
                48,
                49,
                50,
                51,
                52,
                53,
                54,
                55,
                56,
                57,
                58,
                59,
                60,
                61,
                62,
                63,
                64,
                65,
                66,
                67,
                68,
                69,
                70,
                71,
                72,
                73,
                74,
                75,
                76,
                77,
                78,
                79,
                80,
                81,
                82,
                83,
                84,
                85,
                86,
                87,
                88,
                89,
                90,
                91,
                92,
                93,
                94,
                95,
                96,
                97,
                98,
                99,
                100,
                101,
                102,
                103,
                104,
                105,
                106,
                107,
                108,
                109,
                110,
                111,
                112,
                113,
                114,
                115,
                116,
                117,
                118,
                119,
                120,
                121,
                122,
                123,
                124,
                125,
                126,
                127,
                128,
                129,
                130,
                131,
                132,
                133,
                134,
                135,
                136,
                137,
                138,
                139,
                140,
                141,
                142,
                143,
                144,
                145,
                146,
                147,
                148,
                149,
                150,
                151,
                152,
                153,
                154,
                155,
                156,
                157,
                158,
                159,
                160,
                161,
                162,
                163,
                164,
                165,
                166,
                167,
                168,
                169,
                170,
                171,
                172,
                173,
                174,
                175,
                176,
                177,
                178,
                179,
                180,
                181,
                182,
                183,
                184,
                185,
                186,
                187,
                188,
                189,
                190,
                191,
                192,
                193,
                194,
                195,
                196,
                197,
                198,
                199,
                200,
                201,
                202,
                203,
                204,
                205,
                206,
                207,
                208,
                209,
                210,
                211,
                212,
                213,
                214,
                215,
                216,
                217,
                218,
                219,
                220,
                221,
                222,
                223,
                224,
                225,
                226,
                227,
                228,
                229,
                230,
                231,
                232,
                233,
                234,
                235,
                236,
                237,
                238,
                239,
                240,
                241,
                242,
                243,
                244,
                245,
                246,
                247,
                248,
                249,
                250,
                251,
                252,
                253,
                254,
                255,
                256,
                257,
                258,
                259,
                260,
                261,
                262,
                263,
                264,
                265,
                266,
                267,
                268,
                269,
                270,
                271,
                272,
                273,
                274,
                275,
                276,
                277,
                278,
                279,
                280,
                281,
                282,
                283,
                284,
                285,
                286,
                287,
                288,
                289,
                290,
                291,
                292,
                293,
                294,
                295,
                296,
                297,
                298,
                299,
                300,
                301,
                302,
                303,
                304,
                305,
                306,
                307,
                308,
                309,
                310,
                311,
                312,
                313,
                314,
                315,
                316,
                317,
                318,
                319,
                320,
                321,
                322,
                323,
                324,
                325,
                326,
                327,
                328,
                329,
                330,
                331,
                332,
                333,
                334,
                335,
                336,
                337,
                338,
                339,
                340,
                341,
                342,
                343,
                344,
                345,
                346,
                347,
                348,
                349,
                350,
                351,
                352,
                353,
                354,
                355,
                356,
                357,
                358,
                359,
                360,
                361,
                362,
                363,
                364,
                365,
                366,
                367,
                368,
                369,
                370,
                371,
                372,
                373,
                374,
                375,
                376,
                377,
                378,
                379,
                380,
                381,
                382,
                383,
                384,
                385,
                386,
                387,
                388,
                389,
                390,
                391,
                392,
                393,
                394,
                395,
                396,
                397,
                398,
                399,
                400,
                401,
                402,
                403,
                404,
                405,
                406,
                407,
                408,
                409,
                410,
                411,
                412,
                413,
                414,
                415,
                416,
                417,
                418,
                419,
                420,
                421,
                422,
                423,
                424,
                425,
                426,
                427,
                428,
                429,
                430,
                431,
                432,
                433,
                434,
                435,
                436,
                437,
                438,
                439,
                440,
                441,
                442,
                443,
                444,
                445,
                446,
                447,
                448,
                449,
                450,
                451,
                452,
                453,
                454,
                455,
                456,
                457,
                458,
                459,
                460,
                461,
                462,
                463,
                464,
                465,
                466,
                467,
                468,
                469,
                470,
                471,
                472,
                473,
                474,
                475,
                476,
                477,
                478,
                479,
                480,
                481,
                482,
                483,
                484,
                485,
                486,
                487,
                488,
                489,
                490,
                491,
                492,
                493,
                494,
                495,
                496,
                497,
                498,
                499,
                500,
                501,
                502,
                503,
                504,
                505,
                506,
                507,
                508,
                509,
                510,
                511,
                512,
                513,
                514,
                515,
                516,
                517,
                518,
                519,
                520,
                521,
                522,
                523,
                524,
                525,
                526,
                527,
                528,
                529,
                530,
                531,
                532,
                533,
                534,
                535,
                536,
                537,
                538,
                539,
                540,
                541,
                542,
                543,
                544,
                545,
                546,
                547,
                548,
                549,
                550,
                551,
                552,
                553,
                554,
                555,
                556,
                557,
                558,
                559,
                560,
                561,
                562,
                563,
                564,
                565,
                566,
                567,
                568,
                569,
                570,
                571,
                572,
                573,
                574,
                575,
                576,
                577,
                578,
                579,
                580,
                581,
                582,
                583,
                584,
                585,
                586,
                587,
                588,
                589,
                590,
                591,
                592,
                593,
                594,
                595,
                596,
                597,
                598,
                599,
                600,
                601,
                602,
                603,
                604,
                605,
                606,
                607,
                608,
                609,
                610,
                611,
                612,
                613,
                614,
                615,
                616,
                617,
                618,
                619,
                620,
                621,
                622,
                623,
                624,
                625,
                626,
                627,
                628,
                629,
                630,
                631,
                632,
                633,
                634,
                635,
                636,
                637,
                638,
                639,
                640,
                641,
                642,
                643,
                644,
                645,
                646,
                647,
                648,
                649,
                650,
                651,
                652,
                653,
                654,
                655,
                656,
                657,
                658,
                659,
                660,
                661,
                662,
                663,
                664,
                665,
                666,
                667,
                668,
                669,
                670,
                671,
                672,
                673,
                674,
                675,
                676,
                677,
                678,
                679,
                680,
                681,
                682,
                683,
                684,
                685,
                686,
                687,
                688,
                689,
                690,
                691,
                692,
                693,
                694,
                695,
                696,
                697,
                698,
                699,
                700,
                701,
                702,
                703,
                704,
                705,
                706,
                707,
                708,
                709,
                710,
                711,
                712,
                713,
                714,
                715,
                716,
                717,
                718,
                719,
                720,
                721,
                722,
                723,
                724,
                725,
                726,
                727,
                728,
                729,
                730,
                731,
                732,
                733,
                734,
                735,
                736,
                737,
                738,
                739,
                740,
                741,
                742,
                743,
                744,
                745,
                746,
                747,
                748,
                749,
                750,
                751,
                752,
                753,
                754,
                755,
                756,
                757,
                758,
                759,
                760,
                761,
                762,
                763,
                764,
                765,
                766,
                767,
                768,
                769,
                770,
                771,
                772,
                773,
                774,
                775,
                776,
                777,
                778,
                779,
                780,
                781,
                782,
                783,
                784,
                785,
                786,
                787,
                788,
                789,
                790,
                791,
                792,
                793,
                794,
                795,
                796,
                797,
                798,
                799,
                800,
                801,
                802,
                803,
                804,
                805,
                806,
                807,
                808,
                809,
                810,
                811,
                812,
                813,
                814,
                815,
                816,
                817,
                818,
                819,
                820,
                821,
                822,
                823,
                824,
                825,
                826,
                827,
                828,
                829,
                830,
                831,
                832,
                833,
                834,
                835,
                836,
                837,
                838,
                839,
                840,
                841,
                842,
                843,
                844,
                845,
                846,
                847,
                848,
                849,
                850,
                851,
                852,
                853,
                854,
                855,
                856,
                857,
                858,
                859,
                860,
                861,
                862,
                863,
                864,
                865,
                866,
                867,
                868,
                869,
                870,
                871,
                872,
                873,
                874,
                875,
                876,
                877,
                878,
                879,
                880,
                881,
                882,
                883,
                884,
                885,
                886,
                887,
                888,
                889,
                890,
                891,
                892,
                893,
                894,
                895,
                896,
                897,
                898,
                899,
                900,
                901,
                902,
                903,
                904,
                905,
                906,
                907,
                908,
                909,
                910,
                911,
                912,
                913,
                914,
                915,
                916,
                917,
                918,
                919,
                920,
                921,
                922,
                923,
                924,
                925,
                926,
                927,
                928,
                929,
                930,
                931,
                932,
                933,
                934,
                935,
                936,
                937,
                938,
                939,
                940,
                941,
                942,
                943,
                944,
                945,
                946,
                947,
                948,
                949,
                950,
                951,
                952,
                953,
                954,
                955,
                956,
                957,
                958,
                959,
                960,
                961,
                962,
                963,
                964,
                965,
                966,
                967,
                968,
                969,
                970,
                971,
                972,
                973,
                974,
                975,
                976,
                977,
                978,
                979,
                980,
                981,
                982,
                983,
                984,
                985,
                986,
                987,
                988,
                989,
                990,
                991,
                992,
                993,
                994,
                995,
                996,
                997,
                998,
                999,
                1000
            ],
            "Created By": "1593124235542x532656435701719000",
            "Created Date": 1593124246974,
            "Modified Date": 1593124247035,
            "_id": "1593124246666x110956892081881090",
            "_type": "custom.number_list"
        }
    }
}
8 Likes

Thank you so much. This seems to work for me and gave me many ideas of how to control the results. I don’t like exposing data either, this is a great work around.

I also need some queries I’d rather not do by pulling all the data out of the platform so this allows me to do the work inside bubble then output the result for my external systems to react to.

Thanks alot!

Hi, Just wondering how I access this data from my frontend, do I have to add the API in the API connector or is their some way to directly receive the data in my original front-end workflow right after I have scheduled the API workflow


This method doesnt seem to receiving the data returned.

1 Like

I solved this, now I’m having the limited at 50 list problem. Trying to find a way around this (I’m not exporting my whole database don’t worry)

I’ve been exploring this method of returning data, and what I was thinking of doing is having a “show more” button in the results list that the user sees. The show more button would then grab the next 50 results. I would need to build into the workflow the item # to start with, and that number would get passed as a parameter in the request.

I’m curious though – what are you gaining by grabbing data in this way, rather than just the normal way? (In my case, I am exploring it as a way to get Bubble to run an advanced filter server side).

I have an external API that sends data paginated in groups of 500. Long story short but all the data needs to be displayed in the repeating group. I can’t find a way to cycle through the pages on the front end without slowing down the website

I am not saving the data btw, just displaying it

Hi! Struggling with the same issue… did you find out how you did this? Get result from api front end? :slight_smile:

so basically the best way to do this is to the save the data to the database. If thats not an option, you can use pipedream to get around it

does that help?

Thank you very much, it helps! :slight_smile:

1 Like

Thanks for your advice.

But could you please clarify also where and how you got this response? I need to operate with this in a front-end

1 Like

you can find the answer here — How to use API "Return data from API" - #7 by edwardbutcher

Hi, Keith

Thank you for your answer.

Tell me, if I need to nest another list inside the list, do you know how to do it?

For example:

"numbers": [
  {"numbers": 1,
   "sub-numbers":[ 
    1.1
    2.2
   ] 
  }
  {"numbers": 2,
   "sub-numbers":[
    2.1,
    2.2
    ]
   }

or like this (include sub-item)

Keith, this is clever… I ended up making a NumberList, DateList, and TextList too… thanks

1 Like

Just as a note to others, you need to remember to Delete the NumberList row (data) unless you want to accumulate a bunch of unneeded data