Get Array with no fieldId

MansourMansour ✭✭✭✭
edited June 24, 2019 in Questions
Trying to integrate Hubspot with Skuid Native but having issues pulling the following array into fields.
{
    "results": [
        25054251,
        25129831,
        25284327,
        25370947,
        25371816,
        25402825,
        25515091,
        25974488,
        27511859,
        28085871
    ],
    "hasMore": true,
    "offset": 28085871
}

There is no FieldId for me to store the data to the results into individual rows.  

Has anyone had success in pulling these types of arrays into Skuid?

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited June 15, 2019
    This is a good place to use a custom Response Parsing Snippet. You could use the Response Parsing Snippet transform the inbound results array of numbers into an array of objects that's more friendly to Skuid. 

    https://docs.skuid.com/latest/en/data/rest/#intercepting-response-payloads
  • MansourMansour ✭✭✭✭
    edited June 15, 2019
    Hi Zach,

    Thanks for pointing me in the right direction - are there examples of response parsing snippets I could see?

    Any help here would be much appreciated.


  • edited June 20, 2019
    Hey Mansour - 

    Might look like this. I dunno which endpoint you're using, but your intercept payload probably looks something like the below:

    var params = arguments[0],
    $ = skuid.$;
    //grab the response body - this is what Skuid will use to build your records on this GET request
    var responseBody = params.response.body;
    console.log(responseBody);
    //store things for easiness
    var hasMore = responseBody.hasMore;
    var offset = responseBody.offset;
    var results = responseBody.results;
    //Intercept the results, adding an "id" to each number
    for (i = 0; i<results.length; i++){
        if(results[i]){
            results[i] = {"field_id" : results[i]};
        }
    }
    console.log(results);
    return results;
    All this does is add an object with a field_id property per array value.

    Your order of ops is:
    1. Add the js snippet. Note that if you change the snippet's name, it won't change the referenced snippet in the Response Payload snippet field.
    2. Check "Intercept Response Payload" then add your Response snippet. Skuid will run this snippet, then treat whatever it returns as the "real" payload.
    3. Click the model, then click "Add Field". The id of the field should be field_id - exactly matching your objects' key.
    4. Chuck it into a table and check it out. Bada-bing.
  • MansourMansour ✭✭✭✭
    edited June 24, 2019
    First of all, thanks a ton Aaron.  I think we're almost there.  I'm getting 
    [object Object] as the result from the field_id field you sent over. 

    Any idea on what I need to do to fix it?
  • edited June 24, 2019
    For those in the audience, Mansour and I vidchatted this. His snippet was returning the field_id in an object, so he just needed to go down an object.

    That is, it looked like:
    field_id: {field_id: 120938213} 
    So in step #3 above, he made his id:
    field_id.field_id
    I didn't peek too hard at his setup, but here's how mine resolves with the above snippet. The left shows the table. The right shows the array representing the field_ids. If you're poking at this endpoint and are having the same issue, double-check your property's values for those iconic object brackets {}.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!