Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - General Discussion
Answered

Count occurences

(0) ShareShare
ReportReport
Posted on by 340

Hi guys,

I have an HTTP API call returning devices. I would like a way to count how many of the devices are servers, desktops and laptops. From the API call there are 104 devices

{
 "pageDetails": {
 "count": 104,
 "prevPageUrl": null,
 "nextPageUrl": null
 },
 "devices": [
 {
 "id": 281423,
 "uid": "ccbeb8c4-4e87-0a7a-91e9-c98f8de7b155",
 "siteId": 48083,
 "siteName": "",
 "deviceType": {
 "category": "Server",
 "type": "Main System Chassis"
 },
 },
 {
 "id": 281429,
 "uid": "8d682367-7894-267d-ac29-753b8ba8386e",
 "siteId": 48083,
 "siteName": "",
 "deviceType": {
 "category": "Laptop",
 "type": "Notebook"
 },
 },
 {
 "id": 281429,
 "uid": "8d682367-7894-267d-ac29-753b8ba8386e",
 "siteId": 48083,
 "siteName": "",
 "deviceType": {
 "category": "Desktop",
 "type": "Desktop"
 },
	}

After the HTTP call I added a Compose (Compose 2) action

body('HTTP_2')?['devices']

Then I was thinking of adding a Compose for each category

length(body('Compose_2')) - length(replace(body('Compose_2'), 'laptop', ''))
length(body('Compose_2')) - length(replace(body('Compose_2'), 'desktop', ''))
length(body('Compose_2')) - length(replace(body('Compose_2'), 'server', ''))

 I'm just not sure how to compose that expression for each?

 

Thanks,
David

  • da1ve Profile Picture
    340 on at
    Re: Count occurences

    Thank you @SudeepGhatakNZ that worked as expected

  • Verified answer
    SudeepGhatakNZ Profile Picture
    14,376 Most Valuable Professional on at
    Re: Count occurences

    @da1ve ,

     

    Please refer to the attached flow:

    Your JSON is missing a null on line number 108.

    I have also tweaked the JSON schema a bit.

     

  • da1ve Profile Picture
    340 on at
    Re: Count occurences

    Hi @SudeepGhatakNZ , here is the full output (attached)

    Thanks,
    David

     

     

  • SudeepGhatakNZ Profile Picture
    14,376 Most Valuable Professional on at
    Re: Count occurences

    @da1ve 

    You could save the output of body('HTTP_2')['Devices'] in a Compose

    And then add some Filter actions to filter each device type.

    You could then apply length() to the output of each filter.

    I can help you if you provide the JSON output form API

     

     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >