Access nested objects within array when they don't appear in the mapping panel because the first array item is a different type

Hi all,

I’m trying to access data from the Grist API and am having trouble accessing deeply nested objects and arrays. The primary issue is that the arrays that contain the nested objects contain mixed data types, and have an array item at index 1 that is just a string or number, not an object. Since Make only displays the first array item in the mapping panel, the subsequent key:value pairs within objects at index 2 onwards aren’t shown to be able to select.

The bundle output from the API is attached.

Bundle-API-call.txt (11.6 KB)

I want to access the line items to pull out quantity, description and price of each line item. These are nested several levels deep within the References array but I cannot see any of those levels in the mapping panel because of the issue described where the first array item isn’t a nested object. This is what I see:

If I take the raw data, manually remove all the values at index 1 of the arrays I need to access so the first array item is now a nested object, and then bring this data in via a Parse JSON module I can then see the nested object keys in the panel and access them. Here is an iterator which accesses the same data after I’ve manually made these edits and showing the values I want to access (for each line item):

If I add this to the iterator

I then get 2 bundles returned containing all the details of each line item which is getting me much closer to where I need to be

But I can’t work out how to access these same values when I’m working with the unedited API data when these properties are not available to select in the panel.

I’ve tried using {{ }} format but guess I’m doing it wrong as I don’t get the same result as above.

To summarise, how can I get an array of items, with each item containing quantity, description and price from the attached output bundle?

I’d be so grateful if anyone can share their expert wisdom!

I’ve come up with a solution for my problem by creating variables. Sharing below in case anyone comes across this question in the future and I can save you a headache!

The problem

The issue was not being able to select the properties I needed within nested objects in an array, because the Grist API produces arrays with mixed types for reference lists (linked records), like this:

 "References": [
                            "O",
                            {
                                "id": 1,
                                "Title": "New invoice",
                                "Invoice_Number": 57,
                                "Issued": [
                                    "d",
                                    1755561600
                                ],
                                "Number": "INV00057",
                                "Client": [
                                    "O",
                                    {
                                        "id": 2,
                                        "Contact_Name": [
                                            "R",
                                            "Contacts",
                                            5
                                        ],

The first array item being a string rather than an object (“0” in the example above), prevents the nested objects at array position 2 onwards being available in the mapping panel.

How I solved it

I set a variable for each array that I needed to access and used slice() to remove the first array item. e.g. I needed nested data within the References array, so I set a referencesArray variable: {{slice(13.data.records.fields.References; 1)}}. In the next module I could then access properties at the next level down within the References array, so I proceeded to do the same thing for each of the subsequent nested arrays I needed. Here’s my next set of variables:

I used this same approach of creating a variable each time I was given an array that had the format [“x”, { }, { }, …] as an output, in order to be able to access the properties I needed later in the scenario.

I was then able to access all the values I needed to make an API call to DocsAutomator.

(here’s a reference in the Grist community to the mixed array structure which offers an alternative solution that may help others, but for my purposes would have required multiple calls to the Grist API to get the data I already had from the first one, but was just struggling to access)

3 Likes