{
  "name": "Audit SharePoint Online external sharing and anonymous links with Microsoft Graph",
  "nodes": [
    {
      "id": "391d1525-c97e-448d-b9dc-dc65ffbeb812",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -240,
        48
      ]
    },
    {
      "id": "b7e5ccf2-efd4-4f9c-ae10-99bcdf478a36",
      "name": "Sharepoint - Get Sites",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        48
      ]
    },
    {
      "id": "6bb7b44f-2310-4281-a2c3-b71307b5dcc0",
      "name": "Split Out - Sites",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        464,
        48
      ]
    },
    {
      "id": "7b6c6ae8-8ecb-4014-b9ea-22ee0fd83ceb",
      "name": "SharePoint - Get Drives",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        912,
        48
      ]
    },
    {
      "id": "4cc6b4aa-930e-4d30-821e-c13460646a45",
      "name": "Split Out - Drives",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1136,
        48
      ]
    },
    {
      "id": "75787384-eb3f-4522-b1e6-4fe823e0937d",
      "name": "SharePoint - Get Item Permissions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1584,
        -48
      ]
    },
    {
      "id": "bd4f2f37-6ee6-4889-8990-af9f8211da68",
      "name": "Filter Items based on permissions",
      "type": "n8n-nodes-base.code",
      "position": [
        2256,
        48
      ]
    },
    {
      "id": "2f255329-4952-4b66-b6a4-88a6e1854e8b",
      "name": "SharePoint - Get Items",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        256,
        -272
      ]
    },
    {
      "id": "1c02f2f3-2b74-408a-8b22-414e4e2993ed",
      "name": "Split Out - Items",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        480,
        -368
      ]
    },
    {
      "id": "79229b75-eb39-4739-9466-d2e621bb890c",
      "name": "If Item is not a folder",
      "type": "n8n-nodes-base.if",
      "position": [
        704,
        -368
      ]
    },
    {
      "id": "0a640d58-a1b0-4ee3-8f4f-2491d1c2fd1c",
      "name": "If Input is a Folder",
      "type": "n8n-nodes-base.if",
      "position": [
        32,
        -368
      ]
    },
    {
      "id": "2c4cdf8c-c6ae-44c6-9c96-6fb129a49a0f",
      "name": "SharePoint - Get Child Items",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        256,
        -464
      ]
    },
    {
      "id": "23b1b844-83e6-4736-9856-44619eaa201a",
      "name": "Call 'Audit SharePoint for externally shared Items and anonymous permissions'",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1360,
        48
      ]
    },
    {
      "id": "57f5e7da-4606-48f3-b0be-e4e4892baa34",
      "name": "Subworkflow - Get Items",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -192,
        -368
      ]
    },
    {
      "id": "febdef38-e5f5-4876-92c3-6a24de3ca7bb",
      "name": "Recursive call Get Items",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        928,
        -304
      ]
    },
    {
      "id": "e2e85ed5-1175-46ad-a4f3-1c43f1a8fb24",
      "name": "Return All Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1376,
        -368
      ]
    },
    {
      "id": "12e4b940-3092-4cf8-b667-4ba1694cd5ce",
      "name": "Keept Items and Folders",
      "type": "n8n-nodes-base.merge",
      "position": [
        1152,
        -384
      ]
    },
    {
      "id": "8a947652-d218-45e9-ae42-bcaa86f38f7c",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        2032,
        48
      ]
    },
    {
      "id": "b58ee602-1edd-4abe-9c34-3212a747883c",
      "name": "Rename Output for Permissions",
      "type": "n8n-nodes-base.set",
      "position": [
        1808,
        -48
      ]
    },
    {
      "id": "bb15647d-31f2-4731-9ad9-7ad5d8ab0563",
      "name": "Rename Output for Item",
      "type": "n8n-nodes-base.set",
      "position": [
        1808,
        144
      ]
    },
    {
      "id": "e4906c3c-8167-4ce1-938f-5bca326cb859",
      "name": "Set Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        -16,
        48
      ]
    },
    {
      "id": "138d381b-9ff1-4b9b-b994-cf78c65f11a6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        -544
      ],
      "parameters": {
        "width": 592,
        "height": 448,
        "content": "## How it works\n- Fetches all SharePoint sites via Microsoft Graph\n- Retrieves document libraries for each site\n- Recursively traverses folder and file structures\n- Fetches permissions for every item\n"
      }
    },
    {
      "id": "3074474e-494f-4374-9a36-5c8d24433b3c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        240
      ],
      "parameters": {
        "width": 592,
        "height": null,
        "content": "### Notes\n- Requires EntraID Application\n- Use Client Credentials when adding the OAuth2 credentials in n8n\n- Use a schedule trigger to automatically run this\n- Refactor the subworkflow in its own wor"
      }
    },
    {
      "id": "5853d909-6d09-4793-ac72-a11903c3e557",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        -112
      ],
      "parameters": {
        "width": 448,
        "height": 352,
        "content": "## Recursively traverse through items\nFor each drive start recursive process at root level"
      }
    },
    {
      "id": "7db855ff-2d97-424f-a9e0-6faf5f3e6c78",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -496
      ],
      "parameters": {
        "width": 448,
        "height": 352,
        "content": "## If Item is a folder, go into folder"
      }
    },
    {
      "id": "18a03db6-92e4-439d-a036-fd17b085187c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        -496
      ],
      "parameters": {
        "width": 448,
        "height": 352,
        "content": "## Merge Output\nKeep all traversed items: folders and files as each can have its own permissions"
      }
    },
    {
      "id": "64da6e50-8566-4818-b2ed-780f5b535f47",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -112
      ],
      "parameters": {
        "width": 928,
        "height": 352,
        "content": "## Get top level Sharepoint structure\nGets sites and drives as top level entry points for the traversal of their contents; Also filters out contentstorage sites as they are system area created by micr"
      }
    },
    {
      "id": "2c266637-42e9-43bc-b161-224c5ef6b8d1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1536,
        -112
      ],
      "parameters": {
        "width": 656,
        "height": 416,
        "content": "## Combine and filter the outputs"
      }
    },
    {
      "id": "f8a2ba04-c2fb-4515-99be-0b8c97fb3a51",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        -80
      ],
      "parameters": {
        "width": 592,
        "height": 304,
        "content": "## How data is filtered\nWhat `Filter Items based on permissions` does for each input item:\n* Reads your **internal tenant domains** from the “Set Variables” node\n* Scans the item’s `permissions.value`"
      }
    },
    {
      "id": "bc28fdb6-4a3a-4c0a-bf35-0bf7ae7227de",
      "name": "Filter sites",
      "type": "n8n-nodes-base.filter",
      "position": [
        672,
        48
      ]
    },
    {
      "id": "33f787c8-d74e-4a1c-9c6b-834637c5cabe",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -544
      ],
      "parameters": {
        "width": 624,
        "height": 400,
        "content": "## Get Items\nDifferentiates whether to get items of root level drives or to get child items for folders"
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Filter Items based on permissions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter sites": {
      "main": [
        [
          {
            "node": "SharePoint - Get Drives",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Variables": {
      "main": [
        [
          {
            "node": "Sharepoint - Get Sites",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out - Items": {
      "main": [
        [
          {
            "node": "If Item is not a folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out - Sites": {
      "main": [
        [
          {
            "node": "Filter sites",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out - Drives": {
      "main": [
        [
          {
            "node": "Call 'Audit SharePoint for externally shared Items and anonymous permissions'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Input is a Folder": {
      "main": [
        [
          {
            "node": "SharePoint - Get Child Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SharePoint - Get Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Rename Output for Item": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "SharePoint - Get Items": {
      "main": [
        [
          {
            "node": "Split Out - Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sharepoint - Get Sites": {
      "main": [
        [
          {
            "node": "Split Out - Sites",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Item is not a folder": {
      "main": [
        [
          {
            "node": "Keept Items and Folders",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Recursive call Get Items",
            "type": "main",
            "index": 0
          },
          {
            "node": "Keept Items and Folders",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Keept Items and Folders": {
      "main": [
        [
          {
            "node": "Return All Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SharePoint - Get Drives": {
      "main": [
        [
          {
            "node": "Split Out - Drives",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Subworkflow - Get Items": {
      "main": [
        [
          {
            "node": "If Input is a Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive call Get Items": {
      "main": [
        [
          {
            "node": "Keept Items and Folders",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "SharePoint - Get Child Items": {
      "main": [
        [
          {
            "node": "Split Out - Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Rename Output for Permissions": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SharePoint - Get Item Permissions": {
      "main": [
        [
          {
            "node": "Rename Output for Permissions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Set Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call 'Audit SharePoint for externally shared Items and anonymous permissions'": {
      "main": [
        [
          {
            "node": "SharePoint - Get Item Permissions",
            "type": "main",
            "index": 0
          },
          {
            "node": "Rename Output for Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}