Help with inserting DB records based off API JSON retun

So I have some data being returning by a Google function via API. I’m just having a bit of trouble finding a way to get the repeat right or the schema right or something right in order of adding a DB insert step to write the returned data into the DB.

It could be that the way that google returns the data might not work well with Wappler but I’d love some help while I continue to try and figure this out.

The returned data is in a STRUCT format:

"rows [ ] " : “object (Struct` format)”

An object with as many results as can be contained within the maximum permitted reply size.

Which they further explain as:

And the data itself looks a bit like this in the returned API:

"rows": [
          {
            "f": [
              {
                "v": "-9.747449814584897"
              },
              {
                "v": "2021-04-03"
              },
              {
                "v": "2021"
              },
              {
                "v": "Apr"
              },
              {
                "v": "bin_1"
              },
              {
                "v": "Sat"
              }
            ]
          },

I’ve put the repeat in server connect on the Rows array based on the schema, but that only outputs each f, which contains an array of vvalues. Its these v values that I need to write into the DB.

Anyone have any thoughts or things to look into?

You would have a repeat with expression of rows. Inside that repeat, you have another repeat with express f, then inside the 2nd repeat, you perform your inserts.

Rows and f are both arrays, as indicated by the square brackets, which means there can be one or many rows and each row can have one or many f’s.

Thanks for the response @mebeingken.

I did try something like that but will keep at it.

The schema in wappler is picking it up correctly (by using the copy/paste method) as you can see here:

But in the Wappler repeat UI it doesn’t seem to recognise the full hierarchy in that I can put a repeat on Rows, and output f. I can then put a repeat on f but then CAN’T output v.

Even though i can’t output v. If i add a simple setValue inside the f repeat, i do see the v value as an option to select.

I thought that would work… but the end result when i run the API is empty :slight_smile:

I’ll continue to experiment.,

Good luck! Remember that what can be selected in the picker, is only as good as what you’ve setup with the Define Schema on the api action. Maybe your test fetch, or the json response you provided, didn’t have the full schema?

Interestingly, when i create the 2nd repeat, and use the first repeat as the expression, it only puts f as the expression and then won’t show v as an output (even though its clearly mapped out in API schema).

However, if i manually change the expression to include the repeat name, so its repeat.f then it automatically recognises v as an output of that expression:

image

Thinking that this might work though, i only get an error that might actually be a bug?

{"status":"500","message":"Repeater data is not an array or object","stack":"Error: Repeater data is not an array or object\n    at App.repeat (/opt/node_app/lib/modules/core.js:40:19)\n    
at App._exec (/opt/node_app/lib/core/app.js:384:57)\n    
at App.exec (/opt/node_app/lib/core/app.js:324:20)\n    
at App.repeat (/opt/node_app/lib/modules/core.js:72:28)\n    
at App._exec (/opt/node_app/lib/core/app.js:384:57)\n    
at App._exec (/opt/node_app/lib/core/app.js:355:28)\n    
at processTicksAndRejections (internal/process/task_queues.js:97:5)\n    
at async App.exec (/opt/node_app/lib/core/app.js:324:9)\n   
at async App.define (/opt/node_app/lib/core/app.js:314:9)"}

Ya repeater.f wouldn’t be valid.

If repeat1 is the row repeater:

You could try repeat1[$index].f
Which is give me the f array for the Repeat1 array using the current index to get a single row

Or $value.f

Which is give me f from the current value of the row repeater.

Both should work.

Thanks for your help on this Ken. I didn’t use exactly what you said, but I never explained myself properly either. Anyway, with your encouragement i found a solution :slight_smile:

Turns out I didn’t really need the nested repeat anyway, and it was more about setting the values (later to be sued in insert steps) using the f value and its indexes like f[0].v

This is what worked for me in the end:

1 Like

It is often the case that we struggle the most, when we are not clear with our own goal. It happens. :slightly_smiling_face: glad you have it all settled… on to the next challenge.

1 Like

Indeed!