Skip to main content

Notifications

Power Automate - Building Flows
Answered

Count values from JSON

(0) ShareShare
ReportReport
Posted on by 69
Hi everyone,
 
I'm trying to get devices from Intune via a API Call and want to count the returrned devices.
I successfully get the devices via the API Call.
I then parse the JSON from that API Call output to retrieve the devicename and id (needed later in the flow).
Now I want to count the returned devices and set a variable based on the count, say:
returned device=0 devices found, var=0
returned devices =1 device found, var=1
returned devices > 1, var=more devices found
 
 
 

My next idea was to convert the object returned from the API Call to an array and then count that, but I didn't get this working either.
 
Can someone help me with this?
 
Regards,
Sarah
  • Verified answer
    ebels Profile Picture
    ebels 69 on at
    Count values from JSON
    Thanks for you help.
    I converted the JSON to an array and then count the entries within the array to check, how many devices where returned from the API call.
  • ebels Profile Picture
    ebels 69 on at
    Count values from JSON
    If I check the length of the odata.count then there would be no difference between 0 devices found and 1 device found, correct?
    But I need to check if there was 0, 1 or multiple devices found.
  • Chriddle Profile Picture
    Chriddle 7,305 on at
    Count values from JSON
    If it's just about counting the value length, this is already mentioned in the response:
    Just use it from the Dynamic Content
     
     
    If you don't trust this, use the length function:
    length(body('Parse_JSON')?['value'])
     
     
     
  • ebels Profile Picture
    ebels 69 on at
    Count values from JSON
    Hi  @Chriddle,
     
    here's the output of the API Call:
     
    {
      "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#deviceManagement/managedDevices(id,deviceName)",
      "@odata.count": 1,
      "value": [
        {
          "id": "43912cba-0dcc-4794-b166-60ba7d50b01a",
          "deviceName": "my-test-device"
        }
      ]
    }
     
  • Chriddle Profile Picture
    Chriddle 7,305 on at
    Count values from JSON
    I am pretty sure you can do this with 1 expression using xpath().
    But to tell you more, I need an example of the api response.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,475

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,767

Leaderboard