cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LukePWilkins
Helper II
Helper II

Nested Array Extraction Help

I have the following output from a GraphAPI call, of which I cant work out a way to extract the groupTypes and ID. Could someone lend me some guidence please

{
    "statusCode": 200,
    "headers": {
        "Transfer-Encoding": "chunked",
        "Vary": "Accept-Encoding",
        "Strict-Transport-Security": "max-age=31536000",
        "request-id": "1f9171fa-6c37-4877-9a7e-a61da01a929e",
        "client-request-id": "1f9171fa-6c37-4877-8a7e-a61da02a929e",
        "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"Australia Southeast\",\"Slice\":\"E\",\"Ring\":\"4\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"ML1PEPF00004B03\"}}",
        "x-ms-resource-unit": "1",
        "OData-Version": "4.0",
        "Cache-Control": "no-cache",
        "Date": "Sun, 29 May 2022 02:26:02 GMT",
        "Content-Type": "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8",
        "Content-Length": "445"
    },
    "body": {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects(groupTypes,id)",
        "value": [
            {
                "@odata.type": "#microsoft.graph.group",
                "groupTypes": [
                    "DynamicMembership"
                ],
                "id": "badc0e9e-d736-4534-b2c2-7aed3280a035"
            },
            {
                "@odata.type": "#microsoft.graph.group",
                "groupTypes": [
                    "Unified"
                ],
                "id": "14a7c19e-db29-4e5c-82ec-657686b5f27d"
            },
            {
                "@odata.type": "#microsoft.graph.group",
                "groupTypes": [
                    "Unified"
                ],
                "id": "1b8d728a-bf51-4ddd-b167-9e945f734d77"
            }
        ]
    }
}

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
LukePWilkins
Helper II
Helper II

@eliotcole thank you for taking the time to reply.

It would be interesting to see the function syntax in your SELECT FROM field please

View solution in original post

OK, it's not really relevant what I used (because I put your result in a Compose action! 😅), it's relevant what you use to get the code that you listed.

 

So ... let us assume that the name of your Graph API call is just the standard one and you haven't renamed it. Then your From field would look like this:

body('Send_an_HTTP_request')?['body/value']

Or you could use this:

body('Send_an_HTTP_request')?['body']?['value']

Either should pull that array that you have there.

View solution in original post

6 REPLIES 6
eliotcole
Super User
Super User

Hi, @LukePWilkins , have you taken a look at some of the recommendations on the side there?

 

This has come up a few times in the past week and I reckon you'd probably find an easily bent solution there. 👍 🙂

eliotcole
Super User
Super User

Simply Done

Anyway, here you can simple do a select on the body/value array, and create a key of Group Ids, then in the value side put the expression:

get GroupId.jpg

 

 

item()?['groupTypes']

 

 

This will provide each array as is.

 

If you're confident that each one only has one group inside it (ie. it's checked prior to entry), then you can use:

 

 

item()?['groupTypes'][0]

 

 

That will pull the first value from the groupTypes array into that value field.

 

If you only need it for a singular case, that's fine, if you want to manipulate the original input, then you can simply make a compose after you've generated your new value array, and call the original inside a setProperty() function, setting the value property to your newly generated value set. 🙂

 

Going Overboard

If you wanted to be even cleverer you could use an if() statement to set it to a singular value for just one, or the array for more, or even a join() of the array if you still want a singular value.

As an Array:

if(
    greater(
        length(
            item()?['groupTypes']
        ),
        1
    ),
    item()?['groupTypes'],
    item()?['groupTypes'][0]
)

As a String

if(
    greater(
        length(
            item()?['groupTypes']
        ),
        1
    ),
    join(
        item()?['groupTypes'],
        ','
    ),
    item()?['groupTypes'][0]
)

Choice Between Two

With a boolean variable choosing between array/string 😅:

if(
    greater(
        length(
            item()?['groupTypes']
        ),
        1
    ),
    if(
        variables('stringPleaseVAR'), 
        join(
            item()?['groupTypes'],
            ','
        ),
        item()?['groupTypes']
    ),
    item()?['groupTypes'][0]
)

 

LukePWilkins
Helper II
Helper II

@eliotcole thank you for taking the time to reply.

It would be interesting to see the function syntax in your SELECT FROM field please

OK, it's not really relevant what I used (because I put your result in a Compose action! 😅), it's relevant what you use to get the code that you listed.

 

So ... let us assume that the name of your Graph API call is just the standard one and you haven't renamed it. Then your From field would look like this:

body('Send_an_HTTP_request')?['body/value']

Or you could use this:

body('Send_an_HTTP_request')?['body']?['value']

Either should pull that array that you have there.

LukePWilkins
Helper II
Helper II

Hello, that has given me some good guidence. 

Where the return was producing [ "Dynamic ' ] for example, I was able to use the JOIN action to clean it up and return the Dynamic wording as a string.

 

cheers for taking the time to reply

Nice one, mate.

 

If you select yours, or my, or both(!), answers as Solution it'll just close out the thread so folks can find it in the future as a solution to whatever they need it for.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,956)