Convert API response JSON to Array to disaply it on table

Hello there!

I am trying to put data from bigquery response API, into a table to create record types. 

So far, I have been able to get the response from bigquery and convert it to appian values, the response looks like this:

This is the response I get from bigquery api

then, I created a rule to narrow down to the values, but as you can see, the column name does not come from the response, so it displays all the values as rows but on the following way :

so as you see, I do not have columns  there , I guess the best way to go on this, will be to get the JSON response converted to an array, and then pass it to a table but not sure if this is possible, any advise?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Do the column names come back somewhere else in the API response, or are you just expected to know them?

    Either way I suspect you'll have to loop over the response rows and manually construct the necessary dictionary from each row's results.  If each row will always have the exact same number of columns and you can just hardcode the column/property names, then this should be pretty easy.  If there's an expectation that the columns might be variable and/or will need to be named after data that's given in another part of the response, then it's still doable but might be a bit harder.

  • Hello, thanks for your response. 

    From this response from bigQuery no, the column names do not come in the response anywhere, for that, you need to do another request on a different API from bigquery. 

    I get what you are saying of doing a loop, however, I have not found a way to create a table or a way to use loops, is it like on the interfaces or somewhere on the design pane?

  • 0
    Certified Lead Developer
    in reply to rodrigoe0001

    I just mean that you'd loop over the response rows in your handler Expression Rule and create a formatted dictionary that gets passed back to wherever you need it.  For starters:

    createDictionary(
      {"State", "Country", "Type", "Date"},
      {
        "Cali",
        "Argentina",
        "AA",
        today()
      }
    )

  • 0
    Certified Lead Developer
    in reply to rodrigoe0001

    If you're willing, do me a favor and show your API output as "expression", and copy and paste here with the first ~2 or 3 rows worth of data (feel free to sanitize any of it as necessary, i just need the basic structure).  I'm trying to assemble an example expression to try to loop over the rows and create dictionaries, however Appian doesn't easily allow for creating arrays-of-arrays like your output contains, thus at this point I'm hitting a dead end.

  • Thanks a lot Mike, sure thing, here is the requested information:

    {{f: {{v: "Cali"}, {v: "country"}, {v: "AA"}, {v: "1/22/2021 11:47"}, {v: "5/11/2021 13:33"}, {v: "Match Sent"}, {v: "ZR_11607_CAND"}, {v: "5.09e+17"}, {v: "source"}}}, 

    {f: {{v: "name"}, {v: "country"}, {v: "AA"}, {v: "3/22/2021 15:51"}, {v: "5/11/2021 13:16"}, {v: "Pending"}, {v: "ZR_12952_CAND"}, {v: "5.09e+17"}, {v: "source"}}}

    {f: {{v: "name"}, {v: "country"}, {v: "AA"}, {v: "3/8/2021 11:20"}, {v: "5/11/2021 13:18"}, {v: "Proposed"}, {v: "ZR_13933_CAND"}, {v: "5.09e+17"}, {v: "source"}}}

    I am working on using a data type, I was able to show now the correct column names, now I am just trying to figure out how the foreach syntax works in Appian (I'm new here) so maybe that will do it too

  • 0
    Certified Lead Developer
    in reply to rodrigoe0001

    I believe it would end up being something along these lines, plus or minus:

    a!forEach(
      rule!bigQuery().result.body.rows,
      
      createDictionary(
        {"State", "Country", ...}, /* array of all column/property names */
        fv!item.v
      )
    )

Reply Children