Search code examples
jsonhttprequestpower-automate

Why is my Power Automate Parse JSON action output reading as Null instead of as an array?


I am working on a flow to delete versions from excel files in my SharePoint library based on this reference.

I've run into a problem where an Apply to Each step won't read the outputs of a Parse JSON step as an array, although those outputs look fine. Does anyone have any idea what might be wrong?

Editor

Context steps earlier in flow

Including this just to give you an idea of the lead-up steps. I have it filtered down to one Excel file for testing purposes, although the filter will be a permanent fixture, just with fewer limits on the items retrieved.

First Send HTTP action

Expressions here:

URI: _api/web/GetFolderByServerRelativeUrl('{PATH}')/Files('{FilenameWithExtension}')/Versions
Path: @{items('Get_versions_internal')?['{Path}']}
Filename: @{items('Get_versions_internal')?['{FilenameWithExtension}']}

Parse JSON step

I can edit the schema in if needed, but it's so long and I do plan to include the outputs from the flow run below, so I'm going to skip it for now. I've tried the schema from the linked reference, and also generating from a sample of what the Send HTTP step outputs, and it changed nothing.

Testing Compose step

I inserted this Compose step to test the bits in the next step. Expressions:

@{body('Parse_JSON')?['properties']?['d']?['properties']?['results']}
@{items('Get_versions_internal')?['{Path}']}
@{items('Get_versions_internal')?['{FilenameWithExtension}']}
@{body('Parse_JSON')?['properties']?['d']?['properties']?['results']?['items']?['properties']?['ID']}

The troublesome Apply to each action

This is the one giving me trouble when the flow runs. (I'll show that below.) Expressions:

@{body('Parse_JSON')?['properties']?['d']?['properties']?['results']}

Path: @{items('Get_versions_internal')?['{Path}']}
Filename: @{items('Get_versions_internal')?['{FilenameWithExtension}']}
ID: items('Clear_versions_internal')?['items']?['properties']?['ID']

Flow Run

First Send HTTP

This one runs fine.

URI: _api/web/GetFolderByServerRelativeUrl('Internal/CT/zArchive/Older/')/Files('VR Sign-in Sheet.xlsx')/Versions

Body:

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "https://SHAREPOINT_URL/_api/SP.FileVersion577e4298-b42d-4db0-8780-a484d911db2f",
          "uri": "https://SHAREPOINT_URL/_api/SP.FileVersion577e4298-b42d-4db0-8780-a484d911db2f",
          "type": "SP.FileVersion"
        },
        "CreatedBy": {
          "__deferred": {
            "uri": "https://SHAREPOINT_URL/_api/SP.FileVersion577e4298-b42d-4db0-8780-a484d911db2f/CreatedBy"
          }
        },
        "CheckInComment": "",
        "Created": "2023-04-12T00:12:39Z",
        "ID": 512,
        "IsCurrentVersion": false,
        "Length": "20696",
        "Size": 20696,
        "Url": "_vti_history/512/Internal/CT/zArchive/Older/VR Sign-in Sheet.xlsx",
        "VersionLabel": "1.0"
      }
    ]
  }
}

Parse JSON run 1 Parse JSON run 2

Here are the Parse JSON outputs:

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "https://SHAREPOINT_URL/_api/SP.FileVersion13655235-0e65-421f-be0c-c3bdd562c0f3",
          "uri": "https://SHAREPOINT_URL/_api/SP.FileVersion13655235-0e65-421f-be0c-c3bdd562c0f3",
          "type": "SP.FileVersion"
        },
        "CreatedBy": {
          "__deferred": {
            "uri": "https://SHAREPOINT_URL/_api/SP.FileVersion13655235-0e65-421f-be0c-c3bdd562c0f3/CreatedBy"
          }
        },
        "CheckInComment": "",
        "Created": "2023-04-12T00:12:39Z",
        "ID": 512,
        "IsCurrentVersion": false,
        "Length": "20696",
        "Size": 20696,
        "Url": "_vti_history/512/Internal/CT/zArchive/Older/VR Sign-in Sheet.xlsx",
        "VersionLabel": "1.0"
      }
    ]
  }
}

Compose run

The results of the compose step show that it also didn't see the "results" array, but I'm not sure why.

Finally, the failed Apply to each:

Offending step


Solution

  • It looks like you have added a property called properties twice to your expression, which I don't see in your Parse Json outputs.

    Try the below instead:

    body('Parse_Json')?['d']?['results']